subprocess.check_output() 似乎不存在(Python 2.6.5) [英] subprocess.check_output() doesn't seem to exist (Python 2.6.5)
问题描述
我一直在阅读有关 subprocess 模块的 Python 文档(请参阅此处)和它谈到了一个 subprocess.check_output()
命令,这似乎正是我所需要的.
然而,当我尝试使用它时,我得到一个错误,它不存在,当我运行 dir(subprocess)
时,它没有被列出.
我正在运行 Python 2.6.5,我使用的代码如下:
导入子流程subprocess.check_output(["ls", "-l", "/dev/null"])
有人知道为什么会这样吗?
它是在 2.7 中引入的,参见 文档.
如果需要输出,请使用 subprocess.Popen:><预><代码>>>>导入子流程>>>output = subprocess.Popen(['ls', '-l'], stdout=subprocess.PIPE).communicate()[0]
I've been reading the Python documentation about the subprocess module (see here) and it talks about a subprocess.check_output()
command which seems to be exactly what I need.
However, when I try and use it I get an error that it doesn't exist, and when I run dir(subprocess)
it is not listed.
I am running Python 2.6.5, and the code I have used is below:
import subprocess
subprocess.check_output(["ls", "-l", "/dev/null"])
Does anyone have any idea why this is happening?
It was introduced in 2.7 See the docs.
Use subprocess.Popen if you want the output:
>>> import subprocess
>>> output = subprocess.Popen(['ls', '-l'], stdout=subprocess.PIPE).communicate()[0]
这篇关于subprocess.check_output() 似乎不存在(Python 2.6.5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!