By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,217 Members | 1,297 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,217 IT Pros & Developers. It's quick & easy.

Re: Unable to start a process with subprocess Popen()

P: n/a
On Mon, Sep 8, 2008 at 11:50 AM, <du**********@gmail.comwrote:
Hi,

I'm using the subprocess module's Popen() to start a batch file. This
batch file basically calls an exe which also gets started.
Unfortunately, this does not produce any results. I looked into the
Task bar that this exe has started but it does not consume and cpu so
I believet that this exe is not working.
I used the following command to start the batch fiile:

testing = subprocess.Popen([batchFilePath], \
shell = True, \
stdout = subprocess.PIPE, \
stderr = subprocess.PIPE).communicate()[0]
batchFilePath is the path of the batch file.

--
Regrads,
Rajat
Ok, I re-phrase my question:

there is a batch file that executes a exe file. The batch just works
if run from command prompt and produces output to standard output and
the file.

Now, I try to call the same batch file from subprocess.Pope() call.
The batch file gets called and that internally also calls the exe
file.

But, the exe just runs forever i.e. hangs and does not produces output
, atleast not to the file.

Please suggest is there is something wrong with the above code.

Regards,
Rajat
Sep 8 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
aha
On Sep 8, 7:23*am, dudeja.ra...@gmail.com wrote:
On Mon, Sep 8, 2008 at 11:50 AM, *<dudeja.ra...@gmail.comwrote:
Hi,
I'm using the subprocess module's Popen() to start a batch file. This
batch file basically calls an exe which also gets started.
Unfortunately, this does not produce any results. I looked into the
Task bar that this exe has started but it does not consume and cpu so
I believet that this exe is not working.
I used the following command to start the batch fiile:
testing = subprocess.Popen([batchFilePath], \
* * * * * * * * * * * * * * * * * shell = True, \
* * * * * * * * * * * * * * * * * stdout = subprocess.PIPE, \
* * * * * * * * * * * * * * * * * stderr = subprocess.PIPE).communicate()[0]
batchFilePath is the path of the batch file.
--
Regrads,
Rajat

Ok, I re-phrase my question:

there is a batch file that executes a exe file. The batch just works
if run from command prompt and produces output to standard output and
the file.

Now, I try to call the same batch file from subprocess.Pope() call.
The batch file gets called and that internally also calls the exe
file.

But, the exe just runs forever i.e. hangs and does not produces output
, atleast not to the file.

Please suggest is there is something wrong with the above code.

Regards,
Rajat
Hello Rajat,
I would take a look at the thread below, it might help it might not:

http://groups.google.com/group/comp....e15c9c88a5efdc

Also, if you post a larger section of the code I might be able to give
you a hand. Once you've run the testing = subprocess.Popen()

make sure you use a testing.wait()
Sep 8 '08 #2

P: n/a
En Mon, 08 Sep 2008 13:35:21 -0300, <du**********@gmail.comescribió:
cmd = subprocess.Popen([batchFilePath], \
shell = True, \
stdin = subprocess.PIPE,
stdout = subprocess.PIPE, \
stderr = subprocess.PIPE \
)
cmd.stdin.close()
outPipe, errPipe = PipeThread(cmd.stdout),
PipeThread(cmd.stderr)
outPipe.run(), errPipe.run()
retcode = cmd.wait()
out, err = outPipe.getOutput(), errPipe.getOutput()

Although, this solved my problem. But I know there is no need for using
threading in this problem. This problem could've been solved just by the
subprocess module.

I'm unnecessarily using the threading module.
Not only that, you're misusing the Thread class. To actually create a
separate execution thread, you should call outPipe.start() instead of
outPipe.run() (same for errPipe).
Note that if your batch file emits a large output it really may be
necesary to use a separate thread to read the output.

--
Gabriel Genellina

Sep 9 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.