Popen和Python [英] Popen and python

查看:117
本文介绍了Popen和Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在处理一些代码,在命令提示符下运行它时出现错误消息...

Working on some code and I'm given the error when running it from the command prompt...

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]

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

Am I missing something elementary? I wouldn't doubt it. Thanks!

推荐答案

您应该这样做:

import subprocess
subprocess.Popen(cmd, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
# etc.

这篇关于Popen和Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆