【发布时间】:2013-11-19 18:57:25
【问题描述】:
我正在尝试在 python 中执行命令并在 Windows 的命令行中读取其输出。
到目前为止,我已经编写了以下代码:
def build():
command = "cobuild archive"
print "Executing build"
pipe = Popen(command,stdout=PIPE,stderr=PIPE)
while True:
line = pipe.stdout.readline()
if line:
print line
我想在命令行中执行命令 cobuild archive 并读取它的输出。但是,上面的代码给了我这个错误。
File "E:\scripts\utils\build.py", line 33, in build
pipe = Popen(command,stdout=PIPE,stderr=PIPE)
File "C:\Python27\lib\subprocess.py", line 679, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 893, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
【问题讨论】:
-
你需要缩进你的代码
-
在 shell 中输入该命令会发生什么?
标签: python windows command-line