【发布时间】:2013-06-19 23:07:33
【问题描述】:
现在我正在使用 pythonw.exe 运行我的 scrypt,当执行以下命令时出现 cmd:
r = subprocess.call('net stop tomcat7', shell=False)
print r
代码执行时如何让cmd不出现?
【问题讨论】:
-
试试
shell = True。
现在我正在使用 pythonw.exe 运行我的 scrypt,当执行以下命令时出现 cmd:
r = subprocess.call('net stop tomcat7', shell=False)
print r
代码执行时如何让cmd不出现?
【问题讨论】:
shell = True。
尝试将shell参数设置为'True'。
r = subprocess.call('net stop tomcat7', shell=True)
print r
【讨论】:
我将此 startupinfo 与 subprocess.Popen 一起使用(在 this project 中):
subprocess.STARTF_USESHOWWINDOW = 1
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
subprocess.Popen(
[app] + args,
startupinfo=startupinfo,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
【讨论】: