from subprocess import call
call(["python3", "/home/johngr/psdirc/TestBot1.py"]) and call(["python3", "/home/johngr/psdirc/TestBot2.py"]) and call(["python3", "/home/johngr/psdirc/TestBot3.py"])
The call is working but it only runs the first file. I want them all to run in their own terminal windows.
Don't use and
just run one after the other:
call(["python3", "/home/johngr/psdirc/TestBot1.py"])
call(["python3", "/home/johngr/psdirc/TestBot2.py"])
call(["python3", "/home/johngr/psdirc/TestBot3.py"])
If you don't want them to wait for the process to finish before starting the next use Popen:
Popen(["python3", "/home/johngr/psdirc/TestBot1.py"])
Popen(["python3", "/home/johngr/psdirc/TestBot2.py"])
Popen(["python3", "/home/johngr/psdirc/TestBot3.py"])
call
will Run the command described by args. Wait for command to complete, then return the returncode attribute. where Popen
won't wait.
If you want to be sure each process exits with a non-zero exit status use check_call which will raise a CalledProcessError for any non-zero exit status.
To open a terminal for each you can use gnome-terminal
with -e
Execute the argument to this option inside the terminal:
call(['gnome-terminal', '-e', "python3 /home/johngr/psdirc/TestBot1.py"])
call(['gnome-terminal', '-e', "python3 /home/johngr/psdirc/TestBot2.py"])
call(['gnome-terminal', '-e', "python3 /home/johngr/psdirc/TestBot3.py"])
If you want to open tabs you can use --tab -e
:
cmd =['gnome-terminal', '--tab', '-e', 'python3 /home/johngr/psdirc/TestBot1.py',
'--tab', '-e','python3 /home/johngr/psdirc/TestBot2.py','--tab', '-e',
'python 3 /home/johngr/psdirc/TestBot3.py']
call(cmd)
You don't seem to have gnome-terminal so just replace it with lxterminal
:
call(['lxterminal', '-e', 'python3 /home/johngr/psdirc/TestBot1.py'])
Not sure if --tab
option is supported or not, I don't see any reference to it in the documentation.
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