I don't know how the parser work , but why the caret before the variable name?
What mean?
Code: Select all
%^cmdcmdline%
and why this work too?
Code: Select all
echo pipe | echo ^%cmdcmdline^%
is the same?
einstein1969
Moderator: DosItHelp
Code: Select all
%^cmdcmdline%
Code: Select all
echo pipe | echo ^%cmdcmdline^%
einstein1969 wrote:but why the caret before the variable name?
Code: Select all
echo %%cmdcmdline%%
Code: Select all
echo %ThisIsUndefined%
jeb wrote:Hi,
sorry I'm a little bit late for this discussion
But I only want to show the simple cause for the strange behaviour.Code: Select all
C:\>echo pipe | if defined X lss Y echo %^cmdcmdline%
Output wrote:C:\Windows\system32\cmd.exe /S /D /c" if definedX lss Y echo %cmdcmdline% "
As you can see the two tokens just behind the IF are simply combined into one
Sometimes it can help when you see how the parser restructure the line...
jeb
Code: Select all
>echo pipe|if not /i gtr GTR lss echo %^cmdcmdline%
C:\WINDOWS\system32\cmd.exe /S /D /c" if not /iGTR GTR lss echo %cmdcmdline%"
Code: Select all
echo pipe|if not gtr GTR lss echo %^cmdcmdline%
No, it is just an endless loop ("gtrGTR < echo"); cmdcmdline is expanded to:npocmaka_ wrote:And any idea what happens here :Code: Select all
echo pipe|if not gtr GTR lss echo %^cmdcmdline%
Looks like cmdcmdline cannot be expanded?
C:\WINDOWS\system32\cmd.exe /S /D /c" if not gtrGTR lss echo %cmdcmdline%"
Code: Select all
C:\>echo pipe|if /I not 0 lss neq 0lss echo %^cmdcmdline%
C:\WINDOWS\system32\cmd.exe /S /D /c" if /I not 0LSS neq 0lss echo %cmdcmdline%"
C:\>echo pipe|if /I 0 lss equ 0lss echo %^cmdcmdline%
C:\WINDOWS\system32\cmd.exe /S /D /c" if /I 0LSS equ 0lss echo %cmdcmdline%"
C:\>
Code: Select all
echo pipe | cmd /c "if 1 lss 2 more"
dbenham wrote:You can get an IF statement to work normally if you insert an extra layer of CMD /C.
Code: Select all
@echo off
set "myLine=if 1 lss 2 more"
echo pipe | ( %%myLine%%)
jeb wrote:dbenham wrote:You can get an IF statement to work normally if you insert an extra layer of CMD /C.
Ok, but that will start one more CMD.exe instance.
But there exists an even more simple solution with double expansionCode: Select all
@echo off
set "myLine=if 1 lss 2 more"
echo pipe | ( %%myLine%%)
Take notice of the parenthesis around the command
Without the parenthesis you get an error message, that the command %myLine% can't be found.
jeb
Code: Select all
break|if 125^ gtr 124 echo %^cmdcmdline%
Code: Select all
@echo off
for /l %%# in (0,1,9) do (
if %%#^ equ 0 (
echo NULL
) else (
echo %%#
)
)|sort
Code: Select all
(if a equ a echo #)|more
Code: Select all
break|if defined^ cd echo %cmd^cmdline%
Code: Select all
>set z=1
>break|if defined^ z echo #
z was unexpected at this time.
>set neq=1
>break|if defined^ neq echo #
#