Say I have a batch file where in I call a VBScript(which returns the ERRORLEVEL) like:
@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
)
and the test.vbs is like:
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
My question is that upon execution of this batch file........ I am not able to catch the %ERRORLEVEL% generated by my VBScript in my batch script(PS: test.vbs is executing fine when ran individually). Moreover , its a weird output I am getting:
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.
why am I getting "0 was unexpected at this time." error in Batch file. How else can I pass Error code from a vbscript to its parent batch script??
Any help is welcome....... Thanks in advance.
New Edit ,
Thanks PA for your reply.. Actually now I am setting a different variable namely, ERRORLEV as shown below:
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
)
The best part is now event the variable ERRORLEV is getting set/echoed correctly. However I am not able to use it in 'IF' command.. I am getting a output of :
the value of ERRORLEV is :
2
0 was unexpected at this time.
Can you suggest , what might be the case???