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

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

        检索 subprocess.call() 的输出

        Retrieving the output of subprocess.call()(检索 subprocess.call() 的输出)

            <bdo id='UWgAZ'></bdo><ul id='UWgAZ'></ul>

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

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

            1. <tfoot id='UWgAZ'></tfoot>
                <tbody id='UWgAZ'></tbody>
                  <i id='UWgAZ'><tr id='UWgAZ'><dt id='UWgAZ'><q id='UWgAZ'><span id='UWgAZ'><b id='UWgAZ'><form id='UWgAZ'><ins id='UWgAZ'></ins><ul id='UWgAZ'></ul><sub id='UWgAZ'></sub></form><legend id='UWgAZ'></legend><bdo id='UWgAZ'><pre id='UWgAZ'><center id='UWgAZ'></center></pre></bdo></b><th id='UWgAZ'></th></span></q></dt></tr></i><div id='UWgAZ'><tfoot id='UWgAZ'></tfoot><dl id='UWgAZ'><fieldset id='UWgAZ'></fieldset></dl></div>
                • 本文介绍了检索 subprocess.call() 的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何获得使用 subprocess.call() 运行的进程的输出?

                  How can I get the output of a process run using subprocess.call()?

                  StringIO.StringIO 对象传递给 stdout 会出现以下错误:

                  Passing a StringIO.StringIO object to stdout gives this error:

                  Traceback (most recent call last):
                    File "<stdin>", line 1, in <module>
                    File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 444, in call
                      return Popen(*popenargs, **kwargs).wait()
                    File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 588, in __init__
                      errread, errwrite) = self._get_handles(stdin, stdout, stderr)
                    File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 945, in _get_handles
                      c2pwrite = stdout.fileno()
                  AttributeError: StringIO instance has no attribute 'fileno'
                  >>> 
                  

                  推荐答案

                  subprocess.call() 的输出只能重定向到文件.

                  Output from subprocess.call() should only be redirected to files.

                  您应该改用 subprocess.Popen().然后,您可以为 stderr、stdout 和/或 stdin 参数传递 subprocess.PIPE,并使用 communicate() 方法从管道中读取:

                  You should use subprocess.Popen() instead. Then you can pass subprocess.PIPE for the stderr, stdout, and/or stdin parameters and read from the pipes by using the communicate() method:

                  from subprocess import Popen, PIPE
                  
                  p = Popen(['program', 'arg1'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
                  output, err = p.communicate(b"input data that is passed to subprocess' stdin")
                  rc = p.returncode
                  

                  原因是subprocess.call()使用的类文件对象必须有一个真实的文件描述符,从而实现fileno()方法.仅使用任何类似文件的对象都无法解决问题.

                  The reasoning is that the file-like object used by subprocess.call() must have a real file descriptor, and thus implement the fileno() method. Just using any file-like object won't do the trick.

                  请参阅此处了解更多信息.

                  这篇关于检索 subprocess.call() 的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)

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

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

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

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