I try to pipe my command output to variables and then compare if those variables have the same value. However it always return both variables have same value(even though it is not). Below is my code:
@echo off
goto main
:main
setlocal
echo 111 | (set /p readvalue= & set readvalue)
echo 123 | (set /p readvaluebash= & set readvaluebash)
if "%readvalue%"=="%readvaluebash%" goto valid
if NOT "%readvalue%"=="%readvaluebash%" goto invalid
:valid
echo yes
pause
goto finish
:invalid
echo no
pause
goto finish
:finish
endlocal
I always get the yes
result. Anyone know my mistake here? Thanks in advance!
goto
before each entry point. Also, troubleshoot by trying toecho
the values of the variables.echo 111
, next lineset /p readvalue= & set readvalue
, next lineecho 123
, next lineset /p readvaluebash= & set readvaluebash
, or to say it easy line after line notecho 123 | (set....)