Python 2.6.4的Windows版本:有沒有什麼方法可以確定在使用shell = True時subprocess.Popen()是否失敗?當shell = True時,如何確定subprocess.Popen()失敗
POPEN()成功時失敗殼=假
>>> 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
但當殼=真,似乎沒有辦法確定一個POPEN()調用成功與否。
>>> p = subprocess.Popen('Nonsense.application', shell=True)
>>> p
>>> subprocess.Popen object at 0x0275FF90>>>
>>> p.pid
6620
>>> p.returncode
>>>
想法讚賞。
問候, 馬爾科姆
謝謝你的答案。 poll()接着是returncode技術正是我尋找的解決方案。 – Malcolm 2010-05-19 16:59:04