1.

Solve : Unable to get IF condition work in batch script?

Answer»

Below is my code

echo off
echo option CONFIRM off > testupload.txt
echo open winscp >> testupload.txt
echo close >> testupload.txt
echo exit >> testupload.txt
winscp /script=testupload.txt /ini=winscp.ini /log=log1.txt > sri_test.txt
findstr /I /L /M "Still" sri_test.txt > out.txt
echo sri_test.txt >> out.txt
For /f "TOKENS=* delims= " %%a in (out.txt) do set myvar=%%a
echo %myvar%
IF "%myvar"=="sri_test.txt" sri.bat


The issue is if condition is executed irrespective of  %myvar value. I am hardcoding %myvar to "sri_test.txt", still it is not letting me in. What's wrong with DOS?Pls help Quote

Code: [SELECT]IF "%myvar"=="sri_test.txt" sri.bat

Use "%myvar%" not "%myvar"





As foxidrive told you this in alt.msdos.batch, Even when you correct that typo the code will *always* execute sri.bat because you are echoing it into the file and your for loop will set myvar to be the last line of the file.








Discussion

No Comment Found