Mehran Goudarzi
asked on
killall tor && service tor start in Python
i want use this command on my Python script :
killall tor && service tor start
How can i do it on Python ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you use subprocess.Popen, then the process is started, but python does not wait for it to be finished.
The equivalen with subprocess Popen would be.
subprodcess.call() is just a shortcut.
if you use subprocess Popen without the wait function, then you might call
"service tor start" before "killall tor" has been finished.
and the python script would continue executing other python commands before any of the subprocesses had been finished.
The equivalen with subprocess Popen would be.
import subprocess
proc1 = subprocess.Popen(["killall", "tor"])
returncode = proc1.wait()
if returncode == 0:
proc2 = subprocess.Popen(["service", "tor", "start"])
returncode = proc2.wait()
subprodcess.call() is just a shortcut.
if you use subprocess Popen without the wait function, then you might call
"service tor start" before "killall tor" has been finished.
and the python script would continue executing other python commands before any of the subprocesses had been finished.
ASKER
Open in new window
andOpen in new window