Reputation: 11
I'm new to python, still learning What i need to do is to fork a complex command to background and continue th execution of my main program, something like this: I do this from the linux command line (and works ok)
./pgm1 arg1 arg2 arg3 | ./pgm22 arg21 arg22 arg23 arg24 &
so the program goes to background and i can coninue my work.
How can i run the above command in my python program?
Many thanks
Upvotes: 1
Views: 77
Reputation: 180391
You can PIPE the output of the first command to the second using subprocess.Popen:
from subprocess import PIPE,Popen
p = Popen(["./pgm1" ,"arg1" ,"arg2" ,"arg3" ],stdout=PIPE)
p1 = Popen( ["./pgm22", "arg21", "arg22", "arg23" ,"arg24"],stdin=p.stdout,stdout=PIPE)
p.stdout.close()
Popen does not wait for the command to finish.
Upvotes: 1