我已经得到了我用pyInstaller创建一个exe文件一点点Python应用程序:如何强制退出我的Python制作EXE
import subprocess
try:
taskCommand = 'tasklist /FI "ImageName eq pc-client.exe"'
reply = subprocess.Popen(taskCommand, stdout = subprocess.PIPE).communicate()[0]
for line in reply.split("\n"):
if line.startswith("pc-client.exe"):
PID = line.split()[1]
print PID
except:
pass
try:
killCommand = ("TASKKILL /f /t /PID " + PID)
subprocess.Popen(killCommand, stdout = subprocess.PIPE).communicate()[0]
except:
pass
try:
print "Restarting Papercut Client..."
subprocess.Popen(r"\\server\path\to\file\filename.exe", stdout = subprocess.PIPE).communicate()[0]
except:
pass
sys.exit()
当exe文件运行时,它开辟了窗口命令窗口,将运行其代码(它是非交互式的),然后我希望窗口消失时,它完成!
我应该在Python代码的末尾放置什么,以使窗口在完成时关闭。我试过os.quit(),os._exit(),sys.quit()& sys.exit()但是他们都没有关闭窗口!
由于我从我的代码创建一个exe文件,我应该使用别的东西吗?我无法编译noconsole标志,因为它需要它来实际运行命令...
谢谢。
啊,这是有道理的。所以我可以杀死父进程(我的代码)一旦子进程(.exe文件)开始,让它运行? – user3514446
是的,但命令窗口不会消失,因为您通过子进程调用产生了“从提示符中”运行的exe文件。除非我错过了某些东西或误解了目标。 – The4thIceman