为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

ITMISS 2019-06-28 17:03:27
检索子进程的输出。调用()如何使进程的输出运行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'>>>
查看完整描述

3 回答

?
ibeautiful

TA贡献1993条经验 获得超5个赞

如果Python版本>=2.7,则可以使用子进程.检查输出它基本上可以实现您想要的结果(它以字符串的形式返回标准输出)。

简单示例(Linux版本,参见注):

import subprocessprint subprocess.check_output(["ping", "-c", "1", "8.8.8.8"])

请注意ping命令使用的是Linux符号(-c(供计数)。如果您在Windows上尝试此操作,请记住将其更改为-n同样的结果。


查看完整回答
反对 回复 2019-06-28
  • 3 回答
  • 0 关注
  • 528 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信