2011-01-17 25 views

答えて

2

exitステートメントは、バッチファイルを早期に終了させます。

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

他にも述べたように、これは効果的に答えるには余裕があります。

CALLコマンドを実行して別のバッチスクリプトを呼び出し、コールサイトに戻すことについては、this questionを参照してください。

関連する問題