Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个脚本应该坐在那里,愉快地在命令窗口中运行,喷出数据......但我希望在脚本完成或崩溃时自动关闭窗口。该脚本由其他进程自动重启,我不希望我的处理机器被未使用的终端污染。
在紧要关头,我考虑将脚本设置为 Windows 服务,将它们的输出转储到文件中,并且只使用命令窗口“tail -f”输出文件,但我不希望对系统进行重大更改已经很好用了。
当您启动命令行程序时,这是通常的行为。只要进程正在运行,控制台就会一直停留在那里,一旦它(自然或意外)死亡,控制台窗口就会关闭。
这也适用于脚本、批处理文件等。
如果您显式cmd使用批处理文件或程序运行,则应提供/c参数而不是/k.
cmd
/c
/k