简体   繁体   English

Windows:如何在新命令窗口中以某种方式在进程完成或崩溃时关闭窗口?

[英]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.

相关问题 如何运行 Windows 批处理文件但隐藏命令窗口? - How can I run a windows batch file but hide the command window? 如何在没有 window 的情况下运行进程 - How to run process with no window 如何将为Windows CE创建的软件运行到“窗口”选项卡中? - How can i run software created for windows ce into window tab? python:windows:子进程在新命令 window 中打开 a.bat 文件并运行 - python : windows : Subporcess open a .bat file in a new command window and run Boost 进程在新窗口中打开进程 (Windows) - Boost process open process in new window (Windows) 从命令行运行 m 文件时如何隐藏“MATLAB 命令行窗口”? - How do I hide “MATLAB Command Window” when I run an m-file from command line? Windows:隐藏新进程(无窗口) - Windows: start a new process hidden (no window) 我如何运行.exe但保持在同一个命令窗口(不打开新的)? - How do I run a .exe but stay in the same command window (not open a new one)? 如何在 Inno Setup 中不打开新窗口的情况下运行 CMD 命令 - How to run a CMD command without openning a new window in Inno Setup Windows XP 或更高版本 Windows:如何在不显示窗口的情况下在后台运行批处理文件? - Windows XP or later Windows: How can I run a batch file in the background with no window displayed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM