相关疑难解决方法(0)

检索subprocess.call()的输出

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

传递StringIO.StringIO对象stdout会出现此错误:

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'
>>> 
Run Code Online (Sandbox Code Playgroud)

python subprocess pipe stringio

248
推荐指数
7
解决办法
36万
查看次数

从subprocess.communicate()读取流输入

我正在使用Python subprocess.communicate()来从一个运行大约一分钟的进程中读取stdout.

如何stdout以流式方式打印出该流程的每一行,以便我可以看到生成的输出,但在继续之前仍然阻止流程终止?

subprocess.communicate() 似乎立刻提供所有输出.

python subprocess

75
推荐指数
3
解决办法
7万
查看次数

标签 统计

python ×2

subprocess ×2

pipe ×1

stringio ×1