I need to execute two other python scripts from another one. commands look like this:
# python send.py
# python wait.py
This will happen in a loop that will sleep for 1 minute then re-run.
Before executing the commands to start the other scripts I need to make sure they are not still running.
You can use subprocess.Popen to do that, example:
import subprocess
command1 = subprocess.Popen(['command1', 'args1', 'arg2'])
command2 = subprocess.Popen(['command2', 'args1', 'arg2'])
if you need to retrieve the output do the following:
command1.wait()
print command1.stdout
Example run:
sleep = subprocess.Popen(['sleep', '60'])
sleep.wait()
print sleep.stdout # sleep outputs nothing but...
print sleep.returncode # you get the exit value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With