蟒蛇。如何执行系统命令(Windows)avioding控制台?

时间:2013-06-23 07:32:15

标签: python windows console

现在我用pythonw.exe运行我的scrypt,当执行以下命令时,cmd出现:

r = subprocess.call('net stop tomcat7', shell=False)
print r

如何在代码执行时不显示cmd?

2 个答案:

答案 0 :(得分:0)

尝试设置shell参数'True'。

r = subprocess.call('net stop tomcat7', shell=True)  
print r

答案 1 :(得分:0)

我将这个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)