假设我有一个批处理文件,其中我调用了一个 VBScript(它返回 ERRORLEVEL),例如:
@echo off
echo Passing the control to VBSCript.
Cscript test.vbs
if %ERRORLEVEL% EQU 0 (
echo done here!!!!
EXIT /B 0
)
if %ERRORLEVEL% EQU 1
echo EROOR!!!!!!!
EXIT /B 1
)
test.vbs 就像:
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
strComputer = "."
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
strEntry1a = "DisplayName"
strEntry1b = "QuietDisplayName"
strEntry1c = "DisplayVersion"
.......................................
..........some code here...............
.......................................
IF i=0 THEN
WScript.Echo "Congratulations!! Everything is fine......
WScript.Quit 0
ELSE
WScript.Echo "Sorry Mate.. Things out here look bad....
WScript.Quit 1
END IF
我的问题是,在执行此批处理文件时........我无法在我的批处理脚本中捕获我的 VBScript 生成的 %ERRORLEVEL%(PS:单独运行时 test.vbs 执行良好)。此外,我得到一个奇怪的输出:
Passing the control to VBSCript.
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
............................
............................
......VB Code Running........
..........here.............
0 was unexpected at this time.
为什么我会得到“此时 0 出乎意料”。批处理文件中的错误。我还能如何将错误代码从 vbscript 传递到其父批处理脚本?
欢迎任何帮助.......在此先感谢。
新编辑,
感谢 PA 的回复。实际上我现在正在设置一个不同的变量,即 ERRORLEV,如下所示:
IF ERRORLEVEL 0 SET /a ERRORLEV=0
IF ERRORLEVEL 1 SET /a ERRORLEV=1
IF ERRORLEVEL 2 SET /a ERRORLEV=2
echo the value of ERRORLEV is :
echo %ERRORLEV%
if %ERRORLEV% EQU 0 (
echo Nothing is to be Done
EXIT /B 0
)
IF %ERRORLEV% EQU 2 (
echo Let start then.......
EXIT /B 1
)
现在最好的部分是变量 ERRORLEV 被正确设置/回显。但是我无法在“IF”命令中使用它。我得到的输出是:
the value of ERRORLEV is :
2
0 was unexpected at this time.
你能建议一下,可能是什么情况???