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

后端 未结 2 386
心在旅途
心在旅途 2021-01-18 01:40

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

2条回答
  •  有刺的猬
    2021-01-18 01:50

    returncode will work, although it will be None until you've called p.poll(). poll() itself will return the error code, so you can just do

    if a.poll() != 0:
        print ":("
    

提交回复
热议问题