ERRORLEVEL未正确报告

时间:2014-02-06 21:14:40

标签: batch-file batch-processing errorlevel

我正在运行以下windows .bat脚本,我遇到了麻烦。

@echo off
set /p Var1= Drag and drop your .itmsp folder here: 

CALL C:\progra~2\itms\iTMSTransporter -m verify -f %Var1% -u username -p password -o %Var1%\log.txt -s shortname -v eXtreme WONoPause true

IF %ERRORLEVEL% == 0 goto PASS
else goto FAIL

:PASS
blat c:\temp\file.txt -to user@example.com -subject "This has passed"
exit

:FAIL
blat c:\temp\file.txt -to user@example.com -subject "This has failed"
exit

命令运行但ERRORLEVEL似乎不起作用,只报告0,没有别的。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

我会说你不需要启动命令。 IF-ELSE语法错误,但实际上您不需要else部分。我敢打赌你需要引用参数。试试这个:

@echo off
set /p Var1= Drag and drop your .itmsp folder here: 

CALL C:\progra~2\itms\iTMSTransporter -m verify -f "%Var1%" -u username -p password -o "%Var1%\log.txt" -s shortname -v eXtreme WONoPause true

rem fail if ERRORLEVEL >= 1 otherwise continue
IF ERRORLEVEL 1 goto FAIL

blat c:\temp\file.txt -to user@example.com -subject "This has passed"
goto:EOF

:FAIL
blat c:\temp\file.txt -to user@example.com -subject "This has failed"