开发者

: was unexpected at this time

开发者 https://www.devze.com 2023-02-18 19:37 出处:网络
I am creating a bat file that does some basic functions for server builds. The script is made to be somewhat interactive. This allows us to use on script for Production, Dev, or QA. The area of the sc

I am creating a bat file that does some basic functions for server builds. The script is made to be somewhat interactive. This allows us to use on script for Production, Dev, or QA. The area of the script that fails is below

echo Enter User-defi开发者_StackOverflow中文版ned Information about this Server:  
echo Environment:  
echo    1. PROD     
echo    2. QA  
echo    3. Dev  
echo  Choose one:   
CHOICE /C 123  
if errorlevel 1 (set ENVIRONMENTNAME=PROD & set ENVNAME=Production)  
if errorlevel 2 (set ENVIRONMENTNAME=QA & set ENVNAME=Acceptance)  
if errorlevel 3 (set ENVIRONMENTNAME=Dev & set ENVNAME=Development)

Once I am prompted to "Choose One:" I choose either of the options then get the error:

: was unexpected at this time.


Remove the @echo off or echo off commands from the top of the script (or add echo on), and use the resulting output to debug which line causes the offending error.

For optimization purposes, put your if errorlevel commands in descending order. The if errorlevel command triggers when the ERRORLEVEL is the specified number or higher.


I realise this is a rather belated answer, but I've just experienced exactly the same error message, although it was a "set /p" that was causing the problem for me. The line was originally:

set /p Option=Do you want to go ahead and load the data? ([Y]/N): 

and the solution I found was to put double quotes around the prompt text, so:

set /p Option="Do you want to go ahead and load the data? ([Y]/N): "

Don't know if that will help anyone or not, but it solved the problem for me :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号