一尘不染

Popen和Python

python

使用某些代码,从命令提示符运行它时出现错误提示…

NameError: name 'Popen' is not defined

但我同时导入import osimport sys

这是代码的一部分

exepath = os.path.join(EXE File location is here)
exepath = '"' + os.path.normpath(exepath) + '"'
cmd = [exepath, '-el', str(el), '-n', str(z)]

print 'The python program is running this command:'
print cmd

process = Popen(cmd, stderr=STDOUT, stdout=PIPE)
outputstring = process.communicate()[0]

我缺少基本的东西吗?我不会怀疑。谢谢!


阅读 163

收藏
2020-12-20

共1个答案

一尘不染

你应该做:

import subprocess
subprocess.Popen(cmd, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
# etc.
2020-12-20