小编典典

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]

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


阅读 228

收藏
2020-12-20

共1个答案

小编典典

你应该做:

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