Windows:如何在新的命令窗口中运行某些内容,以便在进程完成或崩溃时窗口关闭?

发布于 2024-08-25 05:29:34 字数 196 浏览 4 评论 0原文

我有一个脚本应该放在那里,愉快地在命令窗口中运行,喷出数据......但我希望窗口在脚本完成或崩溃时自动关闭。该脚本由其他进程自动重新启动,我不希望我的处理机器被未使用的终端污染。

在紧要关头,我考虑过将脚本设置为 Windows 服务,将其输出转储到文件中,并且只需使用命令 windows“tail -f”输出文件,但我不希望对系统进行重大更改已经运作良好。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

゛时过境迁 2024-09-01 05:29:34

当您启动命令行程序时,这是通常的行为。只要进程正在运行,控制台就会停留在那里,一旦进程终止(自然或意外),控制台窗口就会关闭。

这也适用于脚本、批处理文件等。

如果您使用批处理文件或程序显式运行 cmd,则应提供 /c 参数而不是 /k

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文