3 回答

TA贡献1850条经验 获得超11个赞
Popen.communicate完成后将设置returncode属性(*)。这是相关的文档部分:
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).
所以您可以做(我没有测试过,但是应该可以):
import subprocess as sp
child = sp.Popen(openRTSP + opts.split(), stdout=sp.PIPE)
streamdata = child.communicate()[0]
rc = child.returncode
(*)发生这种情况的原因是它的实现方式:设置线程以读取子流后,它仅调用wait。

TA贡献1830条经验 获得超9个赞
您首先应确保该过程已完成运行,并且已使用该.wait
方法读取了返回代码。这将返回代码。如果您以后想要访问它,则将其存储.returncode
在Popen
对象中。

TA贡献1863条经验 获得超2个赞
.poll() 将更新返回码。
尝试
child = sp.Popen(openRTSP + opts.split(), stdout=sp.PIPE)
returnCode = child.poll()
另外,在.poll()调用之后,该对象中的返回码可用child.returncode。
添加回答
举报