如何使命令提示符挂起?

编程入门 行业动态 更新时间:2024-10-26 00:21:31
本文介绍了如何使命令提示符挂起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是的,我知道您可能会抱怨说这是一件坏事,但是我还是想这样做!

我正在创建一个批处理程序,最后,我需要将其挂起并且不接受用户输入.我知道一种方法只是创建一个无限循环:

I am creating a batch program and at the end, I need it to hang and not accept user input. I know one method is just creating an infinite loop of:

:pause pause > nul goto pause

但我认为这不是一个好选择.尽管我需要将其挂起,但是我需要能够通过窗口顶部的红色"X"关闭按钮将其关闭.

but I don't think that's a great choice. Although I need it to hang, I need to to be able to be closed via the red 'X' close button at the top of the window.

有什么想法吗?

推荐答案

这对我有用.它将< NUL重定向到self中,以防止 Ctrl + C 损坏,并使用start /b /wait禁止显示终止批处理作业(Y/N)?".提示.

This works for me. It redirects < NUL into self to prevent Ctrl+C from breaking, and uses start /b /wait to suppress the "Terminate batch job (Y/N)?" prompts.

@echo off setlocal >NUL (echo(%* | findstr "\<hang\>" && waitfor redX) rem // *** PUT YOUR MAIN SCRIPT HERE *** echo End of line. rem // ******* END MAIN SCRIPT ********* call :hang goto :EOF :hang start /b /wait "" "%~f0" hang ^<NUL

在脚本的首次启动时,echo(%* | findstr "\<hang\>" >NUL行查找脚本参数"hang".如果找到,该脚本将执行waitfor命令.

On the initial launch of the script, the echo(%* | findstr "\<hang\>" >NUL line looks for a script argument of "hang". If found, the script executes the waitfor command.

通常,可以使用 Ctrl + C 破坏waitfor.但是由于 Ctrl + C 的通常行为被start /b和<NUL击败,因此除非用户执行 Ctrl + 中断或发送应答waitfor信号.

Normally, waitfor can be broken with Ctrl+C. But since the usual behavior of Ctrl+C is defeated by start /b and <NUL, the hanging effect is achieved unless a user does Ctrl+Break or sends the answering waitfor signal.

尽管如此,红色的X仍然有效.

The red X still works, though.

更多推荐

如何使命令提示符挂起?

本文发布于:2023-11-06 17:22:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564313.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:提示符   挂起   使命

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!