处理一些代码,我从命令提示符运行时遇到错误...
NameError: name 'Popen' is not defined
Run Code Online (Sandbox Code Playgroud)
但我已经导入了两个import os和import 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]
Run Code Online (Sandbox Code Playgroud)
我错过了一些基本的东西吗 我不怀疑.谢谢!
Sil*_*ost 32
你应该做:
import subprocess
subprocess.Popen(cmd, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
# etc.
Run Code Online (Sandbox Code Playgroud)
Popen在子进程模块中定义
import subprocess
...
subprocess.Popen(...)
Run Code Online (Sandbox Code Playgroud)
要么:
from subprocess import Popen
Popen(...)
Run Code Online (Sandbox Code Playgroud)