开发者

.bat fails - where is the problem

开发者 https://www.devze.com 2023-02-04 21:25 出处:网络
What could cause running a batch file to开发者_JAVA技巧 terminate in the middle of running?An exit statement will cause a batch file to terminate early.There exists some immediatly stop errors.

What could cause running a batch file to开发者_JAVA技巧 terminate in the middle of running?


An exit statement will cause a batch file to terminate early.


There exists some immediatly stop errors.
But in your special case, the cause is unknown, like the code.

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%#
    )
) 


As others mentioned, this is too open-ended to answer effectively.

Nevertheless, you may want to see this question about needing the CALL command to call another batch script and have it return to the call site.

0

精彩评论

暂无评论...
验证码 换一张
取 消