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

后端 未结 2 442
心在旅途
心在旅途 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:57

    In the first case it fails to start, in the second - it successfully starts shell which, in turn, fails to execute the application. So your process has been properly spawned, exited and waits for you to inquire about its exit code. So, the thing is, unless your shell or environment (e.g. no memory) is utterly broken there's no way Popen itself may fail.

    So, you can safely .poll() and .wait() on it to get all the sad news.

提交回复
热议问题