本文介紹了在 Python 中使用 subprocess.Popen 檢查進程的狀態的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
如果我在 Python 中使用 subprocess.Popen
調用一個進程,如下所示:
If I invoke a process with subprocess.Popen
in Python as follows:
myproc = subprocess.Popen(...).communicate()
查看其狀態的正確方法是什么?不是輸出到 stdout 或 stderr,而是完成后的退出狀態(例如,0 表示成功或另一個表示失敗)?
what is the correct way to see its status? Not its output to stdout or stderr, but its exit status once it's finished (e.g. 0 for success or another for failure)?
推薦答案
returncode
確實是答案,但解決方案不需要復雜.
returncode
is indeed the answer, but the solution doesn't need to be complicated.
process = subprocess.Popen(...)
stdoutdata, stderrdata = process.communicate()
print process.returncode
Python subprocess
文檔中的更多信息.
More info in the Python subprocess
docs.
這篇關于在 Python 中使用 subprocess.Popen 檢查進程的狀態的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!