问题描述
我正在尝试打开第二个批处理文件,并检测它是否通常被用户退出(ctrl + c或x或窗口终止等).因此,我使用关闭后的批处理运行脚本
Im trying to open a 2nd batch file and detect if it normally exited or closed by a user (ctrl+c or x or window termiate etc..)so Im using this following example by Batch run script when closed
@Echo off
set errorlevel=1
start /w %comspec% /c "mode 70,10&title Folder Confirmation Box&color 1e&echo.&echo. Else the close window&pause>NUL&exit 12345"
echo %errorlevel%
pause
我试图保持第一批等待(/W),因为稍后我将检查错误级别但是在关闭第二个批处理文件后,出现诸如^ cterminate batch job(Y/N)的错误?
Im trying to keep 1st batch waiting (/W) since I will check for errorlevel later onBut after closing the 2nd batch file I get an error like ^cterminate batch job (Y/N)?
我通过 https://superuser.com/尝试了该建议问题/35698/如何抑制终止批次工作确认》
使用脚本
rem Bypass "Terminate Batch Job" prompt.
if "%~2"=="-FIXED_CTRL_C" (
REM Remove the -FIXED_CTRL_C parameter
SHIFT
) ELSE (
REM Run the batch with <NUL and -FIXED_CTRL_C
CALL <NUL %1 -FIXED_CTRL_C %*
GOTO :EOF
)
那很好那么,有没有一种方法可以从相同的批处理文件开始并避免终止?还是我必须从同一批次创建一个新批次并调用它?(我不希望他们也看到该文件)
That works quite fine So is there a way of starting from same batch file and avoiding the terminating?Or do I have to create a new batch from same batch and call it?(I don't want them to see the file aswell)
推荐答案
这对我有用:
call :runme start /w "Child Process" %comspec% /c "child.bat & exit 12345" <NUL >NUL 2>NUL
echo %ERRORLEVEL%
goto :eof
:runme
%*
goto :eof
这个想法是在当前脚本中调用一个子例程,而不是调出一个外部脚本.您仍然可以重定向输入和输出以进行子例程调用.
The idea is to call a subroutine in the current script rather than calling out to an external script. You can still redirect input and output for a subroutine call.
这篇关于批处理文件不能禁止“终止工作".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!