0

I am trying with windows batch command. not Getting the result as expected.

i am passing 4 args to a batch file and inside the batch file i am checking if the 4th arg value is "1"

here the code snippet.

IF %%4=="1" (
echo "Error Level is zero"
echo 'Creating web Ears...'
set cd=%CD%
echo "Current Directory: " %cd%
)

Even after passing the exact value 1, if condition doesn't evaluate to true. Can someone please identify in mistake?

mybat.bat x 5 c 1

1
  • Instead of using bat batch files, take a look at power shell - it is much more powerful. Commented Apr 15, 2012 at 18:44

1 Answer 1

2

Found two errors:

  • Use just one %
  • Remove the double quote around 1

IF %4==1 (  
echo "Error Level is zero"  
echo 'Creating web Ears...'  
set cd=%CD%  
echo "Current Directory: " %cd%  
)  

Tested by Command Prompt on Win7 64bit

Sign up to request clarification or add additional context in comments.

1 Comment

If the fourth parameter is empty, the IF statement will break with a message about syntax error. It would be safer to add characters to both sides of the comparison (typically quotation marks, but that isn't a fixed rule, of course), something like this: IF "%4" == "1" (….

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.