Why Does The Popen() Function Behave Differently In Python And Pygtk?
Solution 1:
First, I don't see that you wait for the child process to complete.
What is likely to happen here is that your pygtk starts a child process and exits right away, the python garbage collector destroys the Popen object.
When you run same code in python shell or some other long-running function, Popen gets more time and hopefully child process completes.
To quickly test if this is in fact the problem, try adding time.sleep(1)
after Popen call.
What you should be doing is calling .communicate()
on Popen object to make sure child process does its thing and terminates.
Second, I have come across cases when pygtk program temporarily changes working directory to something else and then changes it back.
To quickly test this case, try to supply full path both to /path/to/prog
as well as infile, outfile, redirect, etc.
Solution 2:
The
OSError: [Errno2] Nosuchfileordirectory
is caused by your Popen call. Subprocess wants a list:
subprocess.Popen(["./prog","infile","outfile",">/dev/null"], cwd="/path/to/prog", stdout=subprocess.PIPE, shell=True)
Post a Comment for "Why Does The Popen() Function Behave Differently In Python And Pygtk?"