Unable to start a process with subprocess Popen()
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Tue Sep 9 14:53:03 EDT 2008
En Mon, 08 Sep 2008 13:35:21 -0300, <dudeja.rajat at gmail.com> escribió:
> 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
More information about the Python-list
mailing list