subprocess considered harmfull?
Uri Nix
Uri.Nix at gmail.com
Sun Sep 25 09:36:47 EDT 2005
Hi all,
I've been trying to use (Python 2.4 on WinXP) the subprocess module to
execute a shell command (nmake in this case), and pass its output to a
higher level.
Using the following snippet:
p =
subprocess.Popen(nmake,stderr=subprocess.PIPE,stdout=subprocess.PIPE, \
universal_newlines=True, bufsize=1)
os.sys.stdout.writelines(p.stdout)
os.sys.stdout.writelines(p.stderr)
Works fine on the command line, but fails when called from within
Visual Studio, with the following error:
File "C:\Python24\lib\subprocess.py", line 549, in __init__
(p2cread, p2cwrite,
File "C:\Python24\lib\subprocess.py", line 609, in _get_handles
p2cread = self._make_inheritable(p2cread)
File "C:\Python24\lib\subprocess.py", line 650, in _make_inheritable
DUPLICATE_SAME_ACCESS)
TypeError: an integer is required
If I replace the functionality with:
p = os.popen4(nmake)
# p[1] = stdout_and_stderr result pipe
p[1].flush()
os.sys.stdout.writelines(p[1].readlines())
All is well.
I have a feeling this has been encountered before (by googling here),
but didn't see any concise answer as to subprocess' robustness.
So what is the matter here? And should I consider the subprocess
module still unstable?
Cheers,
Uri
More information about the Python-list
mailing list