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

    <legend id='IfNzr'><style id='IfNzr'><dir id='IfNzr'><q id='IfNzr'></q></dir></style></legend>

    1. <small id='IfNzr'></small><noframes id='IfNzr'>

      <tfoot id='IfNzr'></tfoot>

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

        如何获取包含管道的 Python 子进程命令的输出?

        时间:2023-07-21

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

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

        • <legend id='DdLrd'><style id='DdLrd'><dir id='DdLrd'><q id='DdLrd'></q></dir></style></legend>
            • <bdo id='DdLrd'></bdo><ul id='DdLrd'></ul>

                    <tbody id='DdLrd'></tbody>
                  本文介绍了如何获取包含管道的 Python 子进程命令的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有:

                  cmd_array = ['head', '-n', str(source_noise_end), "data/noise/" + source + '_16k.dat', '|', 'tail', '-' + str(source_noise_start)]
                  source_noise = subprocess.check_output(cmd_array)
                  

                  该命令在我输入 Linux 时有效.我得到 subprocess.CalledProcessError: Command '['head', '-n', '2366468', 'data/noise/white_16k.dat', '|', 'tail', '-2183988']' 返回非零退出状态 1.

                  The command is valid when I type it into Linux. I get subprocess.CalledProcessError: Command '['head', '-n', '2366468', 'data/noise/white_16k.dat', '|', 'tail', '-2183988']' returned non-zero exit status 1.

                  我做错了什么?

                  推荐答案

                  试试这个:

                  import subprocess
                  
                  # cmd contains shell command
                  cmd="your command shell"
                  
                  process = subprocess.Popen(cmd,shell=True,stdin=None,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
                  # The output from your shell command
                  result=process.stdout.readlines()
                  if len(result) >= 1:
                      for line in result:
                          print(line.decode("utf-8"))
                  

                  这篇关于如何获取包含管道的 Python 子进程命令的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Python subprocess.call - 将变量添加到 subprocess.call 下一篇:运行 git 命令时如何获取子进程标准输出?

                  相关文章

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

                        <bdo id='2Ujxw'></bdo><ul id='2Ujxw'></ul>

                      <tfoot id='2Ujxw'></tfoot>
                      <legend id='2Ujxw'><style id='2Ujxw'><dir id='2Ujxw'><q id='2Ujxw'></q></dir></style></legend>