当 Windows 上的 Python 脚本完成时,Window 不会关闭,直到启动的程序退出
Window does not close when Python script on Windows is finished, until launched program exits
下面的 python 脚本工作正常,除了 shell window 保持打开状态。
file = open("C:\Documents and Settings\User1\Desktop\BPanel\BadePanel\SteelUsage.bsu", "a+")
input = raw_input("Please enter project name:")
input = input.upper ()
for line in file.readlines():
if input in line:
print "Project name already exists, executing BadePanel"
import time
time.sleep(4)
import subprocess
subprocess.call(['C:\Documents and Settings\User1\Desktop\BPanel\BadePanel\BadePanel.exe'])
exit(subprocess)
file.write (input+"\n")
print "Project name written to file, executing BadePanel"
import time
time.sleep(4)
import subprocess
subprocess.call(['C:\Documents and Settings\User1\Desktop\BPanel\BadePanel\BadePanel.exe'])
exit(subprocess)
file.close()
shell window 仅在我关闭执行的程序后终止 (BadePanel.exe)
我希望脚本在 shell window 中显示打印的文本,等待 4 秒,执行程序,然后退出。
谢谢
来自文档:
subprocess.call()
Run the command described by args. Wait for command to complete, then return the returncode attribute.
因此 .call()
函数只会在 BadePanael.exe 完成后 returns。
相反,尝试:
print "Project name written to file, executing BadePanel"
time.sleep(4)
subprocess.Popen(['C:\Documents and Settings\User1\Desktop\BPanel\BadePanel\BadePanel.exe'])
sys.exit(0)
下面的 python 脚本工作正常,除了 shell window 保持打开状态。
file = open("C:\Documents and Settings\User1\Desktop\BPanel\BadePanel\SteelUsage.bsu", "a+")
input = raw_input("Please enter project name:")
input = input.upper ()
for line in file.readlines():
if input in line:
print "Project name already exists, executing BadePanel"
import time
time.sleep(4)
import subprocess
subprocess.call(['C:\Documents and Settings\User1\Desktop\BPanel\BadePanel\BadePanel.exe'])
exit(subprocess)
file.write (input+"\n")
print "Project name written to file, executing BadePanel"
import time
time.sleep(4)
import subprocess
subprocess.call(['C:\Documents and Settings\User1\Desktop\BPanel\BadePanel\BadePanel.exe'])
exit(subprocess)
file.close()
shell window 仅在我关闭执行的程序后终止 (BadePanel.exe)
我希望脚本在 shell window 中显示打印的文本,等待 4 秒,执行程序,然后退出。
谢谢
来自文档:
subprocess.call()
Run the command described by args. Wait for command to complete, then return the returncode attribute.
因此 .call()
函数只会在 BadePanael.exe 完成后 returns。
相反,尝试:
print "Project name written to file, executing BadePanel"
time.sleep(4)
subprocess.Popen(['C:\Documents and Settings\User1\Desktop\BPanel\BadePanel\BadePanel.exe'])
sys.exit(0)