【问题标题】:ERRORLEVEL not reporting correctlyERRORLEVEL 未正确报告
【发布时间】:2014-02-06 21:14:39
【问题描述】:

我正在运行以下 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,没有别的。请问有什么建议吗?

【问题讨论】:

  • 这里有更新。错误级别没有重新调整 0 以外的任何内容
  • 抱歉,更改了问题以反映我现在的位置。

标签: batch-file batch-processing errorlevel


【解决方案1】:

我会说你不需要启动命令。 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"

【讨论】:

  • 对不起,TomT,这不起作用。两个 blat 命令都不执行。
  • 我相信线索在“命令在单独的窗口中运行” - iTMSTransporter 似乎是一个批处理文件,因此需要 call 否则执行将转移到目标没有返回点。这也可以解释为什么没有一个到达blat 命令。
  • 没有错误信息,命令仍然运行,然后窗口关闭,blat 命令都不执行。
  • 抱歉,弄错了。该命令现在运行,它返回 1(失败),但 ERRORLEVEL 错误地报告为 0。
  • “它返回 1(失败)”是什么意思?如果 ERRORLEVEL 为 0,如何返回 1?打印出来了吗?
猜你喜欢
  • 2021-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多