Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712:::: Diverse tests for the CMD echoer and parser.::@echo offsetlocal enableextensions
:::: Simple tests for the CMD echoer.::echo --------- Testing CMD echoer ---------@echo on
if 1==1 echo j1|(echo j2) else echo j3
(echo a 1>&2|echo a 1>&2) 2>&1
echo 1@echo 2@@echo 3@@@echo 4
:echo x1::echo x2@:echo y1@::echo y2@:::echo y3
@@:echo z1@@::echo z2
foobarechofoobar parameterecho parameter
toto>NULtoto> NULtoto >NULtoto > NUL
toto>NUL 2>&1toto> NUL 2>&1toto >NUL 2>&1toto > NUL 2>&1
a&ba& ba &ba & b
a||ba|| ba ||ba || b
a&&ba&& ba &&ba && b
:: a|b:: a| b:: a |b:: a | b
if 1==1 (echo lol) else (echo boom)
if 1==1 (echo lol) else (echo boom)
for /l %%l in (1,1,5) do (echo %%l)
for /l %%l in (1,1,5) do (echo %%l)
for /l %%l in (1,1,5) do (@@@echo %%l)
if 1==1 @echo hiif 1==1 (@echo heh)if 1==0 (@echo lol) else @echo betterif 1==0 (@echo lol) else (@echo better2)
(a)(a b)
:: An empty parenthesized block is considered to be an error.:: ()
:::: Tests for delayed expansion.::
@echo offsetlocal enableextensionssetlocal enabledelayedexpansion
echo --------- Testing Delayed Expansion ---------
:: Checking exclamation point escapingset ENDV= ^(an open-source operating system^)echo This is ReactOS^^!%ENDV%echo Hello!echo Hello!!echo Hello!!!echo Hello^^^! "^!"
:: The following tests are adapted from:: https://ss64.com/nt/delayedexpansion.html
echo "Hello^World"echo "Hello^World!"
:: Checking expansionset "_var=first"set "_var=second" & Echo %_var% !_var!
:: Checking expansion and replacementset var1=Hello ABC how are youset var2=ABCset result=!var1:%var2%=Developer!echo [!result!]
:: Test of FOR-loopset COUNT=0for /l %%v in (1,1,4) do ( set /A COUNT=!COUNT! + 1 echo [!COUNT!])echo Total = %COUNT%
set "com[0]=lol0"set "com[1]=lol2"set "com[2]=lol4"set "com[3]=lol6"set "com[4]=lol8"set "com[5]=lol10"
for /l %%k in (1,1,5) do ( echo(!com[%%k]! if /I "%%k" equ "5" echo OHLALA)
:::: Re-enable the command echoer::@echo on
setlocal disabledelayedexpansion
echo %~DP0
set test=abcset abc=def
echo %echo %%echo %%%echo %%%%
echo %test%echo %test%%echo %%test%echo %%test%%echo %%%test%%%
echo !test!echo !!test!!
endlocalsetlocal enabledelayedexpansion
:::: Regular and Delayed variables::
echo !echo !!echo !!!echo !!!!echo !a!echo !!a!!
set a=b:: Will display becho !!a!!set b=c:: Will still display becho !!a!!
echo %test%echo %test%%echo %%test%echo %%test%%echo %%%test%%%
echo %!test!%echo !%test%!echo !!test!!:: That other one is the same as the previous one.echo !^!test^!!echo !^^!test^^!!echo !test!echo !test!!echo !!test!echo !!test!!echo !!!test!!!
set proj=XYZecho !%proj%_folder!echo !!proj!_folder!
set %proj%_folder=\\server\folder\echo !%proj%_folder!echo !!proj!_folder!
:::: Delayed variables in blocks::
if 1==1 ( set "pc=T" echo pc == !pc!
set i=3 set "!pc!!i!=5"
echo other pc == !pc! and !pc!!i! == !!pc!!i!! echo other pc == !pc! and !pc!!i! == !^!pc^!^!i^!! echo other pc == !pc! and !pc!!i! == ^!!pc!!i!^! echo other pc == !pc! and !pc!!i! == ^!^!pc^!^!i^!^! set "trol=!pc!!i!" echo the var was !trol!
set "!pc!N=!i!" echo updated !pc!N == !!pc!N! echo updated !pc!N == !^!pc^!N! echo updated !pc!N == ^!!pc!N^! echo updated !pc!N == ^!^!pc^!N^! set "trol=!pc!N" echo updated !pc!N == !trol!)
:: Parsing FOR, IF and REM commands.:::: Note: wrong syntaxes for FOR, IF, REM or parsing operators:: are considered syntactic errors and batch running stops.:: For all other commands, execution continues.::
@echo on
echo --------- Parsing FOR, IF and REM commands ---------
fOr@space@@space@@space@@tab@@tab@ /d@space@@space@@tab@ %%d iN (*)@space@@space@@tab@ do eCHo %%d:for /asdf:: for /d %%d in (*) do echo %%d:: for /d %%d in (*) do echo %%~fdfor /d %%d in (*) do echo %%~edfor /d %%d in (*) do echo %~d0:fOr@tab@@space@@space@@space@@space@@space@@space@@space@@space@@tab@/l@space@@tab@ %%c@space@@space@@tab@ iN@tab@ (1,1,5)@space@@space@@tab@ Do@space@@space@@tab@@space@@tab@ echo@tab@@space@@space@@space@@space@@tab@@tab@%%c
iF@space@@space@@tab@ 457@space@@tab@@space@@tab@neQ@space@@space@@tab@ 458@space@@tab@ (@space@@tab@ echo@space@@tab@ %~d0 ) eLSe (@space@@space@@tab@ echo $~d0@space@@tab@ )
::: if 457 nea 458 (echo %~d0) eLSe (echo $~dp):if 457 nea 458 (echo yo) else (echo ya):if 457 leq 458 (rem/? /d):: if 457 leq 458 ( if 457 nea 458 (echo hi) else (echo yo) )
iF@space@@space@@tab@ "2147483647"@space@@space@@tab@ gEq@space@@tab@@space@@tab@ "2147483648"@space@@tab@ (Echo Larger)@space@@space@@tab@ Else@space@@tab@ (:Echo Smaller)ecHO sMaLlEr)
iF@space@@space@@tab@eRrOrlevel 0 echo hi!
:: rem@tab@@space@@tab@ /df@space@@space@@tab@ /d
rEM /v@space@@tab@/dREm@space@@space@@space@@tab@@tab@ /drEm REM2 /dreM@space@@tab@ /d@space@@tab@ >@space@@tab@ NUL:reM /?/d
:: These commands, even commented out via the parser comment colon,:: cause parsing errors even when being commented out.:: Replace the two '%' by a single one to see the effects.:::echo %~f0 %%~dp %~p1:echo %%~d0 $~dp:echo %%~dp::echo %%~b0
:::: Parsing random commands::
echo --------- Parsing random commands ---------
:: Parsing these commands should fail (when being un-commmented).:@a ( b & |: a ( b & |
:: If goto fails, batch stops. (Done OK in ROS' cmd):goto /asdf whatever
dir > NUL &(b)
setlocal enabledelayedexpansion
echo %~dp0
set SOMEVAR=C:\ReAcToSrem %SOMEVAR% |
Set "_var=first"Set "_var=second" & Rem %_var% !_var!Set "_var=third" & Echo %_var% !_var!
endlocal
:::: Parsing line continuations, either from parenthesized blocks:: or via the escape caret.:: It may be informative to manually run this test under CMD:: with cmd!fDumpTokens and cmd!fDumpParse flags enabled.::
echo --------- Parsing line continuations ---------
(a & bcd):::: Parsed as::: '('[ '&'[a, CRLF[b, CRLF[c,d] ] ] ]::
(a && bcd):::: Parsed as::: '('[ CRLF['&&'[a,b], CRLF[c,d]] ]::
(a & b)
(a & b)
(a & bc & d)
(a & ^bc & d):::: Parsed as::: '('[ '&'[a, CRLF[b, '&'[c,d] ] ]::
(a & bcd):::: Parsed as::: '('[ '&'[a, CRLF[b, CRLF[c,d] ] ] ]::
(a && bcd):::: Parsed as::: '('[ CRLF['&&'[a,b], CRLF[c,d]] ]::
(a || bcd):::: Parsed as::: '('[ CRLF['||'[a,b], CRLF[c,d]] ]::
(ab & cd):::: Parsed as::: '('[ CRLF[a, '&'[b, CRLF[c,d]]] ]::
(ab && cd):::: Parsed as::: '('[ CRLF[a, CRLF['&&'[b,c], d]] ]::
(abc && d):::: Parsed as::: '('[ CRLF[a, CRLF[b, '&&'[c,d]]] ]::
(abc & d):::: Parsed as::: '('[ CRLF[a, CRLF[b, '&'[c,d]]] ]::
(ab
cd):::: Parsed as::: '('[ CRLF[a, CRLF[b, CRLF[c,d] ] ] ]::
REM foo^bar^baz trol^
if 1==1 (echo a) else (echo b)
if 1==1 (echo a) else (echo b)
if 1==1 (echo a) else (echo b)
if 1==1 (echo a) else (echo b)
REM if 1==1 (^REM echo aREM ) ^REM elseREM (^REM echo bREM )
REM if 1==1 (^REM echo aREM ) ^REM else^REM (^REM echo bREM )
REM if 1==1 (^REM echo aREM ) ^REM else^REM (REM echo bREM )
if 1==1 (^echo a)
if 1==1 (^@echo a)
(foo ^bar)
(foo ^&& barbaz)
(foo ^ && barbaz)
REM (foo^REM && barREM bazREM )
(foo^barbaz)
(foo &^& barbaz)
(^foobar)
(
foo ^bar)
(
foo ^&& barbaz)
(
foo ^ && barbaz)
REM (REMREMREM foo^REM && barREM bazREM )
(
foo^barbaz)
(
foo &^& barbaz)
(
^foobar)
:::: Tests for Character Escape and Line Continuation::
(^"!pc::^=^!^")
(^"!pc::^=^!^")
(^"!pc::^=^!^")
(^"!pc::^=^% New line %!^")
REM @ 2>&1 ( ( dir) ) && lol
echo & ^&&lol
REM echo & ^REM ^REM &&lol
trol ^&&lol
trol^&&lol
REM (echo hi)^REM &&lol
rem trol(^line@rem trol2""^line2:trol3^line3
echo trol^line
:echo trol^line
@echo off
:::: Finished!::echo --------- Finished --------------goto :EOF