3 回答

TA貢獻1850條經(jīng)驗 獲得超11個贊
Popen.communicate完成后將設(shè)置returncode屬性(*)。這是相關(guān)的文檔部分:
Popen.returncode
The child return code, set by poll() and wait() (and indirectly by communicate()).
A None value indicates that the process hasn’t terminated yet.
A negative value -N indicates that the child was terminated by signal N (Unix only).
所以您可以做(我沒有測試過,但是應(yīng)該可以):
import subprocess as sp
child = sp.Popen(openRTSP + opts.split(), stdout=sp.PIPE)
streamdata = child.communicate()[0]
rc = child.returncode
(*)發(fā)生這種情況的原因是它的實現(xiàn)方式:設(shè)置線程以讀取子流后,它僅調(diào)用wait。

TA貢獻1830條經(jīng)驗 獲得超9個贊
您首先應(yīng)確保該過程已完成運行,并且已使用該.wait
方法讀取了返回代碼。這將返回代碼。如果您以后想要訪問它,則將其存儲.returncode
在Popen
對象中。

TA貢獻1863條經(jīng)驗 獲得超2個贊
.poll() 將更新返回碼。
嘗試
child = sp.Popen(openRTSP + opts.split(), stdout=sp.PIPE)
returnCode = child.poll()
另外,在.poll()調(diào)用之后,該對象中的返回碼可用child.returncode。
添加回答
舉報