1

I have a batch code which creates certain variables. However, I want to add an IF statement so that if the user enters "Technology" for the first variable, it then creates another variable and asks for additional information. A python script then reads these variables for further processing.

Here is the code:

set constraint_type=1 set constraint_technology=1 set /p constraint_type="Enter constraint type (E.g. "Equipment" or "Technology"): " IF /I !constraint_type!=="Technology" set /p constraint_technology="Enter Technology name: " cmd /k python "script.py" %constraint_type% %constraint_technology% @echo on 

The code runs but the user isn't prompted for the constraint_technology variable. Am I missing something?

2
  • IF /I !constraint_type!=="Technology" --> IF /I "%constraint_type%"=="Technology" (normal % expansion, and quotes to avoid trouble with empty entry) Commented Jan 10, 2017 at 12:28
  • @aschipfl - Awesome, thanks for the tip ;) Commented Jan 10, 2017 at 12:29

1 Answer 1

1

You probably did not enable delayed expansion

!constraint_type! wouldn't evaluate without it. Also remove the quotes, because batch won't do it, so comparison will always be false since user won't put quotes in the input.

even better fix: use standard env. var delimiters, works in all cases,

IF /I %constraint_type%==Technology 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer but the issue still remains.
You're absolutely right, works great now. Many thanks for your answer :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.