Python passing data - new terminal

Permabanned
Joined
26 Jun 2010
Posts
77
I'm stuck.

I have two scripts, i need a line(s) of code in script one, that when script one is finished it automatically run script 2 in a new terminal.

I've found:

xterm -e "command"

Which doesn't really work, it runs it in an xterm windows - not a gnome terminal and it also doesn't finish script one, it hangs of sorts.

I also heard of Pexpect but i have no idea how to use it.

So what i need:

Script one is finishing, it then starts script 2 but script 1 then needs to keep going.

Both are python scripts.

Any ideas on this? :confused:
 
Last edited:
Soldato
Joined
7 Apr 2004
Posts
4,212
You should be able to do it using the subprocess module.

Something like:

Code:
import subprocess

myprocess = subprocess.Popen(mysecondscript, shell=True, stdout=subprocess.PIPE)
myprocess.wait()
print myprocess.returncode

That should launch your second script, and make script1 wait until the second script is done.
 
Soldato
Joined
7 Apr 2004
Posts
4,212
I need script one to start script two, but then carry on. It can't wait - both of the scripts need to run in unison at the end.

Just remove the myprocess.wait() line above then, this will cause script1 to execute script2 and forget about it, i.e continue its execution. Script2 will keep running even if script1 terminates. So after the subprocess.Popen() call, both scripts will be running and there will be no waiting involved.

That what you're after or am I missing something?
 
Permabanned
OP
Joined
26 Jun 2010
Posts
77
Just remove the myprocess.wait() line above then, this will cause script1 to execute script2 and forget about it, i.e continue its execution. Script2 will keep running even if script1 terminates.

That's exactly what i'm after.

I shall try this later when i'm back on my main machine.

Thank you. :p
 
Permabanned
OP
Joined
26 Jun 2010
Posts
77
That doesn't seem to work, i also forgot to mention i need the second terminal to stay open, not run in the background or open then close.
 
Back
Top Bottom