what rem and if (and may be for) have against pipes?
Posted: 20 Apr 2014 09:46
I already know that for rem and if have some weird parsers and looks they have problems with pipes. Well ..for has no just is incapable to parse commands that end with pipe. But rem and if are weird:
0. FOR is disappointing well behaving
1. REM breaks the script I have nothing to do with this
2.Take a look at IF errors (hint - with no pipe these errors should be printed only in case of comprison with wrong syntax)
Well I suppose the tiny hint above is not enough. IF is a little bit different when it comes to comparisons and other operations.So:
2.1 When something is piped to IF ERRORLEVEL / IF EXIST / IF CMDEXTVERSION / IF DEFINED the
(here starts the second list with slash delimited words) ERRORLEVEL/EXIST/CMDEXTVERSION/DEFINED are ignored and IF is forced to do a non working comparison with preserved pipe (and == comparison does not work )
2.2 When something is piped to IF "a" equ/neq/.. "a" the IF wants two comparison commands and none of both works (and == is working )
I'm scandalized !!! And excited (btw. Could anybody else confirm this? Currently I'm testing on 32b XP Home/Laptop and for a while I'll have no access to my powerful Win 8.1 x64 - what are the results with you? )
Is this known behavior?
Of course I'm going to make more tests about comparisons , but wanted to share this so much
@echo off
rem set errorlevel to o
color
echo ----------------
echo -- if tests --
echo ---------------
echo --if "a" equ "b"
echo pipe|if "a" equ "b" more
echo --if "a" equ "b"
echo pipe|if "a" equ "a" more
echo --if errorlevel 0
echo pipe|if errorlevel 0 more
echo --if errorlevel #
echo pipe|if errorlevel # more
echo --if errorlevel 0 break
echo pipe|if errorlevel 0 rem
echo --if exist c:\
echo pipe|if exist c:\ more
echo ----------------
echo -- rem tests --
echo ---------------
echo -- rem
echo pipe| rem
rem these two exist the script
rem echo -- (rem)
rem echo pipe| (call rem)& more
rem echo --call rem & more
rem echo pipe| call rem & more
echo -----------------
echo -- for tests ---
echo -----------------
echo --for /l
echo pipe|for /l %%t in (1,1,2) do more
echo --"for /f %%t in ('echo nopipe') do more"
echo pipe|for /f %%t in ('echo nopipe') do more
echo --"for /f %%t in ('more') do echo %%t"
echo pipe|for /f %%t in ('more') do echo %%t
echo --"for /f %%t in ('more^|') do more"
echo pipe|for /f %%t in ('more^|') do (echo %%t)
0. FOR is disappointing well behaving
1. REM breaks the script I have nothing to do with this
2.Take a look at IF errors (hint - with no pipe these errors should be printed only in case of comprison with wrong syntax)
Well I suppose the tiny hint above is not enough. IF is a little bit different when it comes to comparisons and other operations.So:
2.1 When something is piped to IF ERRORLEVEL / IF EXIST / IF CMDEXTVERSION / IF DEFINED the
(here starts the second list with slash delimited words) ERRORLEVEL/EXIST/CMDEXTVERSION/DEFINED are ignored and IF is forced to do a non working comparison with preserved pipe (and == comparison does not work )
Code: Select all
echo --if errorlevel "b" neq "b" more
echo pipe| if errorlevel "b" neq "b" more
echo --if errorlevel "b" neq "b" more
echo pipe| if errorlevel "b" neq "b" more
2.2 When something is piped to IF "a" equ/neq/.. "a" the IF wants two comparison commands and none of both works (and == is working )
Code: Select all
@echo off
echo --if errorlevel "b" neq "b" more
echo pipe| if errorlevel "b" neq "b" more
echo --if errorlevel "b" neq "b" more
echo pipe| if errorlevel "b" neq "b" more
echo --if "z" equ equ "b" more
echo pipe|if "z" equ equ "b" more
echo --if "z" equ neq "b" more
echo pipe|if "z" equ neq "b" more
echo --if "z"=="b" more
echo pipe|if "z"=="b" echo pipe
echo --if "b"=="b" more
echo pipe|if "b"=="b" echo pipe2
echo --if "b"=="b" more
echo pipe|if "b"=="b" more
I'm scandalized !!! And excited (btw. Could anybody else confirm this? Currently I'm testing on 32b XP Home/Laptop and for a while I'll have no access to my powerful Win 8.1 x64 - what are the results with you? )
Is this known behavior?
Of course I'm going to make more tests about comparisons , but wanted to share this so much