• <legend id='YxniI'><style id='YxniI'><dir id='YxniI'><q id='YxniI'></q></dir></style></legend>

    <tfoot id='YxniI'></tfoot>

  • <i id='YxniI'><tr id='YxniI'><dt id='YxniI'><q id='YxniI'><span id='YxniI'><b id='YxniI'><form id='YxniI'><ins id='YxniI'></ins><ul id='YxniI'></ul><sub id='YxniI'></sub></form><legend id='YxniI'></legend><bdo id='YxniI'><pre id='YxniI'><center id='YxniI'></center></pre></bdo></b><th id='YxniI'></th></span></q></dt></tr></i><div id='YxniI'><tfoot id='YxniI'></tfoot><dl id='YxniI'><fieldset id='YxniI'></fieldset></dl></div>

        • <bdo id='YxniI'></bdo><ul id='YxniI'></ul>

        <small id='YxniI'></small><noframes id='YxniI'>

        使用 Python 子进程通信方法时如何获取退出代码?

        时间:2023-07-22

      1. <legend id='8Hk7L'><style id='8Hk7L'><dir id='8Hk7L'><q id='8Hk7L'></q></dir></style></legend>

            • <bdo id='8Hk7L'></bdo><ul id='8Hk7L'></ul>
            • <small id='8Hk7L'></small><noframes id='8Hk7L'>

              1. <tfoot id='8Hk7L'></tfoot>
              2. <i id='8Hk7L'><tr id='8Hk7L'><dt id='8Hk7L'><q id='8Hk7L'><span id='8Hk7L'><b id='8Hk7L'><form id='8Hk7L'><ins id='8Hk7L'></ins><ul id='8Hk7L'></ul><sub id='8Hk7L'></sub></form><legend id='8Hk7L'></legend><bdo id='8Hk7L'><pre id='8Hk7L'><center id='8Hk7L'></center></pre></bdo></b><th id='8Hk7L'></th></span></q></dt></tr></i><div id='8Hk7L'><tfoot id='8Hk7L'></tfoot><dl id='8Hk7L'><fieldset id='8Hk7L'></fieldset></dl></div>
                  <tbody id='8Hk7L'></tbody>
                  本文介绍了使用 Python 子进程通信方法时如何获取退出代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  使用 Python 的 subprocess 模块和 communicate() 方法时如何检索退出代码?

                  How do I retrieve the exit code when using Python's subprocess module and the communicate() method?

                  相关代码:

                  import subprocess as sp
                  data = sp.Popen(openRTSP + opts.split(), stdout=sp.PIPE).communicate()[0]
                  

                  我应该换一种方式吗?

                  推荐答案

                  Popen.communicate 将在完成时设置 returncode 属性(*).以下是相关文档部分:

                  Popen.communicate will set the returncode attribute when it's done(*). Here's the relevant documentation section:

                  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).
                  

                  所以你可以这样做(我没有测试它,但它应该可以工作):

                  So you can just do (I didn't test it but it should work):

                  import subprocess as sp
                  child = sp.Popen(openRTSP + opts.split(), stdout=sp.PIPE)
                  streamdata = child.communicate()[0]
                  rc = child.returncode
                  

                  <小时>

                  (*) 发生这种情况是因为它的实现方式:在设置线程来读取孩子的流之后,它只是调用 wait.

                  这篇关于使用 Python 子进程通信方法时如何获取退出代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何为 popen 指定工作目录 下一篇:使用 Python 进行交互式输入/输出

                  相关文章

                    1. <legend id='ZxE5h'><style id='ZxE5h'><dir id='ZxE5h'><q id='ZxE5h'></q></dir></style></legend>
                      <i id='ZxE5h'><tr id='ZxE5h'><dt id='ZxE5h'><q id='ZxE5h'><span id='ZxE5h'><b id='ZxE5h'><form id='ZxE5h'><ins id='ZxE5h'></ins><ul id='ZxE5h'></ul><sub id='ZxE5h'></sub></form><legend id='ZxE5h'></legend><bdo id='ZxE5h'><pre id='ZxE5h'><center id='ZxE5h'></center></pre></bdo></b><th id='ZxE5h'></th></span></q></dt></tr></i><div id='ZxE5h'><tfoot id='ZxE5h'></tfoot><dl id='ZxE5h'><fieldset id='ZxE5h'></fieldset></dl></div>
                    2. <tfoot id='ZxE5h'></tfoot>
                      • <bdo id='ZxE5h'></bdo><ul id='ZxE5h'></ul>

                      <small id='ZxE5h'></small><noframes id='ZxE5h'>