How to determine subprocess.Popen() failed when shell=True

Posted by Malcolm on Stack Overflow See other posts from Stack Overflow or by Malcolm
Published on 2010-05-18T22:19:12Z Indexed on 2010/05/18 22:30 UTC
Read the original article Hit count: 402

Filed under:
|
|

Windows version of Python 2.6.4: Is there any way to determine if subprocess.Popen() fails when using shell=True?

Popen() successfully fails when shell=False

>>> import subprocess
>>> p = subprocess.Popen( 'Nonsense.application', shell=False )
Traceback (most recent call last):
  File ">>> pyshell#258", line 1, in <module>
    p = subprocess.Popen( 'Nonsense.application' )
  File "C:\Python26\lib\subprocess.py", line 621, in __init__
    errread, errwrite)
  File "C:\Python26\lib\subprocess.py", line 830, in
_execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

But when shell=True, there appears to be no way to determine if a Popen() call was successful or not.

>>> p = subprocess.Popen( 'Nonsense.application', shell=True )
>>> p
>>> subprocess.Popen object at 0x0275FF90&gt;&gt;&gt; 
>>> p.pid
6620
>>> p.returncode
>>>

Ideas appreciated.

Regards, Malcolm

© Stack Overflow or respective owner

Related posts about python

Related posts about subprocess