4

I have a problem in using variables in command prompt. Based on the value of the environment variable, i want to execute a few commands in a batch file. The code is below:

SET CONFIGURATION=Release

if "CONFIGURATION"=="Release"
(copy c:\python26\test1.py d:\testfiles
copy c:\case.jpg d:\images
)
else
(copy c:\python26\test2.py d:\testfiles
copy c:\debug.jpg d:\images
)

This is what I want to do. I am new to using these kind of scripts. So I don't have much information. Please help me with this.

0

2 Answers 2

6

Batch files have a somewhat special syntax

So your code should look like

SET CONFIGURATION=Release

if "%CONFIGURATION%"=="Release" (
  copy c:\python26\test1.py d:\testfiles
  copy c:\case.jpg d:\images
) else (
  copy c:\python26\test2.py d:\testfiles
  copy c:\debug.jpg d:\images
)

It's important, that the brackets are on the same line of if, ELSE

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

Comments

0

When using the variable later, after set, you will surround the variable with percent signs, like so:

if %CONFIGURATION% == "release" ...

1 Comment

Hi Gabriel,Thanks for the help. but it does not seem to work for me. I did exactly this . SET configuration==release if %configuration%=="release" (echo success) else ( echo failure) . this printed failure :|

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.