When running a secondary python script:
- Is it possible to run a
subprocess.Popen
, orsubprocess.call
or evenexecfile
in a new terminal? (as in simply a different terminal than the current terminal where the script is run). - Alternatively, if before running my program (main), I open two terminals first, can I then point the secondary script to the second terminal? (so somehow getting the ID of open terminals, and then using a specific one among them, to perform the subprocess).
An example, two subprocesses to be run, first.py
should be called first, only then the second is called, second.py
. Because the two scripts first.py
and second.py
are interdependent (as in first.py
goes to wait mode, until second.py
is run, then first.py
resumes, and I don't know how to make this communication work between them in terms of subprocesses.)
import subprocess
command = ["python", "first.py"]
command2 = ["python", "second.py"]
n = 5
for i in range(n):
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
p2 = subprocess.Popen(command2, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True:
output = p.stdout.readline().strip()
print output
if output == 'stop':
print 'success'
p.terminate()
p2.terminate()
break
Framework (Ubuntu, python 2.7)