简体   繁体   中英

Windows: how can I run something in a new command window in such a way that the window closes when the process finishes or crashes?

I have a script that is supposed to sit there, happily running in a command window, spewing out data... but I want the window to close automatically when the script finishes or crashes. The script is auto-restarted by other processes and I don't want my processing machines to become polluted with unused terminals.

In a pinch, I have considered setting up the scripts as windows services that dump their output to a file and just having the command windows "tail -f" the output files, but I"d prefer not to make major changes to a system that already works well.

When you start a command line program that's the usual behavior. The console will stay there as long as the process is running and once it dies (naturally or by accident) the console window closes.

This also holds true for scripts, batch files and the like.

If you explicitly run cmd with a batch file or program, then you should provide the /c argument instead of /k .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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