检索子进程的输出。调用()

检索子进程的输出。调用()

如何使进程的输出运行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'>>>


ITMISS
浏览 529回答 3
3回答

ibeautiful

如果Python版本>=2.7,则可以使用子进程.检查输出它基本上可以实现您想要的结果(它以字符串的形式返回标准输出)。简单示例(Linux版本,参见注):import subprocessprint subprocess.check_output(["ping", "-c", "1", "8.8.8.8"])请注意ping命令使用的是Linux符号(-c(供计数)。如果您在Windows上尝试此操作,请记住将其更改为-n同样的结果。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python