Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281@echo offmkdir foobarcd foobarecho file1 > file1
rem Basic test of command line. Note a section prefix per commandrem to resync, as wine does not output anything in these cases yet.echo --- Test 1cmd.exe /c echo Line1cmd.exe /c echo "Line2"echo --- Test 2cmd.exe /c echo Test quotes "&" workecho --- Test 3cmd.exe /c echo "&"echo --- Test 4cmd.exe /c echo "<"echo --- Test 5cmd.exe /c echo ">"echo --- Test 6cmd.exe /c echo "\"echo --- Test 7cmd.exe /c echo "|"echo --- Test 8cmd.exe /c echo "`"echo --- Test 9cmd.exe /c echo """echo --- Test 10echo on > file3@type file3@echo offecho --- Test 11cmd.exe /c echo on >file3@type file3@echo offecho --- Test 12cmd.exe /c "echo passed1"echo --- Test 13cmd.exe /c " echo passed2 "echo --- Test 14cmd.exe /c "dir /ad ..\fooba* /b"echo --- Test 15cmd.exe /cecho No whitespaceecho --- Test 16cmd.exe /cecho --- Test 17cmd.exe /c@space@echo --- Test 18rem Ensure no interactive prompting when cmd.exe /c or /kecho file2 > file2cmd.exe /c copy file1 file2 >nulecho No prompts or I would not get here1rem - Try cmd.exe /k as wellcmd.exe /k "copy file1 file2 >nul && exit"echo No prompts or I would not get here2
rem Nonexistent variable expansion is as per command line, i.e. left as-iscmd.exe /c echo %%hello1%%cmd.exe /c echo %%hello2cmd.exe /c echo %%hello3^:h=t%%cmd.exe /c echo %%hello4%%%%
rem Cannot issue a call from cmd.exe /ccmd.exe /c call :hello5
rem %1-9 has no meaningcmd.exe /c echo one = %%1
rem for loop vars need expandingcmd.exe /c for /L %%i in (1,1,5) do @echo %%i
rem goto's are ineffectivecmd.exe /c goto :fredcmd.exe /c goto eof
rem - %var% is expanded at read time, not execute timeset var=11cmd.exe /c "set var=22 && setlocal && set var=33 && endlocal && echo var contents: %%var%%"
rem - endlocal ineffective on cmd.exe /c linescmd.exe /c "set var=22 && setlocal && set var=33 && endlocal && set var"set var=99
rem - Environment is inherited okcmd.exe /c ECHO %%VAR%%
rem - Exit workscmd.exe /c exit
cd ..rd foobar /s /q
rem - Temporary batch filesecho @echo 0 > "say.bat"echo @echo 1 > "say one.bat"echo @echo 2 > "saytwo.bat"echo @echo 3 > "say (3).bat"echo @echo 4 > "say .bat"echo @echo 5 > "bazbaz(5).bat"
echo ------ Testing invocation of batch files ----------call say onecall "say one"call "say"" one"call "say onecall :setError 0call say" one"if errorlevel 2 echo error %ErrorLevel%call say "one"call :setError 0call s"ay oneif errorlevel 2 echo error %ErrorLevel%call :setError 0call s"aytwoif errorlevel 2 echo error %ErrorLevel%call say (3)call "say (3)"call :setError 0call say" (3)"if errorlevel 2 echo error %ErrorLevel%call :setError 0call say" "(3) prints 4?!if errorlevel 2 echo error %ErrorLevel%
echo ------ Testing invocation with CMD /C -------------cmd /c say onecmd /c "say one"call :setError 0cmd /c "say"" one"if errorlevel 2 echo error %ErrorLevel%cmd /c "say onecall :setError 0cmd /c say" one"if errorlevel 2 echo error %ErrorLevel%cmd /c say "one"call :setError 0cmd /c s"ay oneif errorlevel 2 echo error %ErrorLevel%call :setError 0cmd /c s"aytwoif errorlevel 2 echo error %ErrorLevel%cmd /c say (3)call :setError 0cmd /c say" (3)"if errorlevel 2 echo error %ErrorLevel%call :setError 0cmd /c say" "(3) prints 4?!if errorlevel 2 echo error %ErrorLevel%call :setError 0rem Deliberately invoking a fully qualified batch name containing a bracketrem should fail, as a bracket is a command delimiter.cmd /c "bazbaz(5).bat"if errorlevel 1 echo Passed
echo ---------- Testing CMD /C quoting -----------------cmd /c @echo "hi"call :setError 0cmd /c say" "oneif errorlevel 2 echo error %ErrorLevel%cmd /c @echo "\"\\"\\\"\\\\" "\"\\"\\\"\\\\"rem ---- all 5 conditions met, quotes preservedcmd /c "say one"rem cond 1 - /scmd /s/c "say one"cmd /s/c ""say one""rem cond 2 - not 2 quotescmd /c "say onecall :setError 0cmd /c "say"" one"if errorlevel 2 echo error %ErrorLevel%rem cond 3 - special char - first test fails on Vista, W2K8!cmd /c "say (3)"cmd /c ""say (3)""rem cond 4 - no spaces (quotes make no difference here)cmd /c saytwocmd /c "saytwo"cmd /c "saytworem cond 5 - string between quotes must be name of executablecmd /c "say five"echo @echo 5 >"say five.bat"cmd /c "say five"
echo ------- Testing CMD /C qualifier treatment ------------rem no need for space after /ccmd /csay onecmd /c"say one"cmd /c"say onecmd /c=say onecmd /c,say onecmd /c;say onerem non-options are ignored before /c; quotes are not treated speciallycmd "/c"say onecmd ignoreme/c say onecmd abc "def ghi/c say one"cmd -\@$*'"/c say oneecho echo bar > foo.batcmd /qq/c foocmd /q "xyz /c foo"del foo.bat
echo --------- Testing special characters --------------echo @echo amp > "say&.bat"call say&echo @echo ( > "say(.bat"call say(echo @echo ) > "say).bat"call say)echo @echo [ > "say[.bat"call say[echo @echo ] > "say].bat"call say]echo @echo { > "say{.bat"call say{echo @echo } > "say}.bat"call say}echo @echo = > "say=.bat"call say=echo @echo sem > "say;.bat"call say;setlocal DisableDelayedExpansionecho @echo ! > "say!.bat"call say!endlocalsetlocal EnableDelayedExpansioncall say!endlocalecho @echo %%%% > "say%%.bat"call say%%echo @echo ' > "say'.bat"call say'echo @echo + > "say+.bat"call say+echo @echo com > "say,.bat"call say,echo @echo ` > "say`.bat"call say'echo @echo ~ > "say~.bat"call say~
echo --------- Testing parameter passing --------------echo @echo 1:%%1,2:%%2 > tell.batcall tell 1call tell (1)call tell 1(2)call :setError 0call tell(1)if errorlevel 2 echo error %ErrorLevel%call :setError 0call tell((1))if errorlevel 2 echo error %ErrorLevel%call :setError 0call tell(1)(2)if errorlevel 2 echo error %ErrorLevel%call :setError 0call tell(1);,;(2)if errorlevel 2 echo error %ErrorLevel%call :setError 0call tell;1 2if errorlevel 2 echo error %ErrorLevel%call :setError 0call tell; 1, ;2if errorlevel 2 echo error %ErrorLevel%call :setError 0call tell;1;;2if errorlevel 2 echo error %ErrorLevel%call tell "p "1 p" "2call tell p"1 p";2
echo --------- Testing delimiters and parameter passing --------------echo @echo 0:%%0,1:%%1,2:%%2,All:'%%*'> tell.batcall;tell 1 2call tell 1 2==call==tell==1==2call tell(1234)call tell(12(34)call tell(12;34)echo --------- Finished --------------del tell.bat say*.* bazbaz*.batexit:setErrorexit /B %1