批处理脚本选择分支未执行问题咨询:请求排查语法错误
Let's walk through the key syntax and logic problems that are preventing your if blocks from running correctly:
1. Variable Definition Has Extra Spaces
Your line set /P var = "What is your option a or b" has a critical issue: the space between var and = means the actual variable name created is var (with a trailing space), not var. When you reference %var% later, it's empty—so your if conditions never match "A" or "B".
Fix: Remove the spaces around the equals sign:
set /P var="What is your option a or b: "
2. Invalid Command Parameter in the Second if Block
You have a misplaced space in - mode:edit—the hyphen and mode should be joined together as -mode:edit. Extra spaces here will confuse the infordbcl.exe command and cause it to fail (or not run as intended).
3. Working Directory Mismatch
The first if block changes directories to C:\Program Files\Infor\Mongoose\Tools, but the second if block doesn't. If infordbcl.exe isn't in your system's PATH, the second command won't find the executable.
Fix: Move the cd command outside both if blocks to ensure both operations run in the correct directory:
cd /d "C:\Program Files\Infor\Mongoose\Tools"
(The /d flag ensures it switches drives if needed.)
4. Case Sensitivity for User Input
Right now, your script only recognizes uppercase "A" or "B"—if the user enters lowercase "a" or "b", the conditions won't trigger.
Fix: Add the /i flag to your if statements to make matches case-insensitive:
if /i "%var%" == "A" (...)
Full Corrected Script
Here's the revised version with all fixes applied, plus a basic invalid input check:
@echo off setlocal enabledelayedexpansion echo What operation would you like to perform? echo a: Create a new web server echo or echo b: Edit root URL for an existing web server set /P var="Enter your option (a/b): " :: Handle invalid input if /i not "%var%"=="a" if /i not "%var%"=="b" ( echo Invalid option! Please run the script again and enter 'a' or 'b'. pause exit /b 1 ) cd /d "C:\Program Files\Infor\Mongoose\Tools" if /i "%var%" == "A" ( infordbcl.exe addwebserver -name:sample -product:Mongoose -rooturl:https://uscovwmongoose3 ) if /i "%var%" == "B" ( infordbcl.exe addwebserver -name:sample -product:Mongoose -rooturl:https://mongoose.com -mode:edit ) endlocal
内容的提问来源于stack exchange,提问作者surya sindhuja

