.bat失败 - 问题在哪里

时间:2011-01-17 10:36:45

标签: windows batch-file

什么可能导致批处理文件在运行过程中终止?

3 个答案:

答案 0 :(得分:2)

exit语句将导致批处理文件提前终止。

答案 1 :(得分:0)

存在一些立即停止错误。 但在你的特殊情况下,原因是未知的,如代码。

rem error1 - Invalid % Expansion
rem %~

rem error2 - call REM /?
set "switch=/?" 
call rem %%switch%%

rem error3 - stackoverflow
:stack
call :stack

rem error4 - call caret crash only with Vista
set "caret=^"
call echo %%caret%%

rem error5 - Long expansion
rem shows that expansion of % in a line is before the rem ignores the rest of the line
rem The expansion results in a very long line with 10000 characters, the batch stops immediatly
setlocal EnableDelayedExpansion
set "longStr=."
for /L %%c in (1,1,13) DO set longStr=!longStr:~0,2500!!longStr:~0,2500!
rem Now we heave a string with 5000 characters, and build a rem line with 2 times 5000 = 10000 characters
rem The next line crashes the batch file
rem tokenOne %longStr% %longStr%
(
    ENDLOCAL
    goto :eof
)

rem error 6 - %%var<LF> error, crashes only sometimes
set critical_content=hello%%~^

echo $
for %%a in (1 ) do (
    for %%x in (4) do (
        rem #%critical_content%#
    )
) 

答案 2 :(得分:0)

正如其他人所说,这太开放无法有效回答。

尽管如此,您可能希望this question看到需要CALL命令来调用另一个批处理脚本并让它返回到调用站点。