简体   繁体   English

Windows 命令提示符 CMD 关闭

[英]Windows Command Prompt CMD Close

命令

In Python, How can I check and close such cmd windows like in picture?在 Python 中,如何检查和关闭这样的 cmd windows,如图所示? This code should control and find which cmd is finished and idle like in picture, then close it.此代码应控制并找到哪个 cmd 已完成并如图所示空闲,然后将其关闭。 I don't want a code which is waiting to close it.我不想要等待关闭它的代码。 It should be a detached program.它应该是一个独立的程序。 By the way, the image is a sample.顺便说一句,图像是一个样本。 It is not my original problem.这不是我原来的问题。

You can think that you have a window or several windows opened and waiting like this, how can they be closed?你可以认为你有一个 window 或几个 windows 这样打开等待,它们怎么能关闭? There is a condition to close a command prompt.有一个条件可以关闭命令提示符。 This condition is that program on that prompt should be done.这个条件是应该完成那个提示下的程序。 Command prompts on which a program runs should not be closed.不应关闭运行程序的命令提示符。 Moreover, this program should intervene externally and afterwards.此外,该程序应在外部和事后进行干预。

I can't solve with taskkill or psutil.我无法用 taskkill 或 psutil 解决。 They always see the state of cmd as running.他们总是看到 cmd 的 state 正在运行。 More specifically, you can look at code snippet below,更具体地说,您可以查看下面的代码片段,

os.system("start /B start cmd.exe @cmd /k python helloworld.py & exit")

It doesn't close the command prompt.它不会关闭命令提示符。

I don't know if you're looking for this solution, but you can add "& exit" after your script, and that will close CMD.我不知道您是否正在寻找此解决方案,但您可以在脚本后添加“& exit”,这将关闭 CMD。

For example:例如:

python script.py & exit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM