Reputation: 607
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?
Upvotes: 1
Views: 59
Reputation: 140168
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
Upvotes: 1