[英]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. 在紧急情况下,我曾考虑将脚本设置为Windows服务,将其输出转储到文件中,而仅使命令窗口将“ tail -f”输出文件,但是我不希望对系统进行重大更改已经运作良好。
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
. 如果使用批处理文件或程序显式运行
cmd
,则应提供/c
参数而不是/k
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.