Im writing an bat file to rename an file with a new name, and i need to
get the ERRORLEVEL value from this bat file into an VBScript.
I m always getting an zero errorlevel when i run the bat file from the
script
My code is below...

BAT FILE
---------------------------------
@echo off
:: do something that sets errorlevel 1
REN fil fils
echo %ERRORLEVEL%
(this would return an 1 when run from dos prompt)

VBScript
-------------------------------------
Dim fso, wShell, i
Set wShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
i = wShell.Run ("C:\test1.bat", 1, True)
WScript.Echo i
(This should return 1, but returns only 0)

Y is this happening, is there anything wrong with my logic

Rajesh.N

Re: help needed by Walter

Walter
Mon Jul 17 02:17:23 CDT 2006

Your very last statement "echo %ERRORLEVEL%" runs successfully, so it
returns an exit code of 0 to the script! If you remove this statement it
will solve your problem.

<gemini.rajesh@gmail.com> wrote in message
news:1153117083.223438.215840@s13g2000cwa.googlegroups.com...
: Im writing an bat file to rename an file with a new name, and i need to
: get the ERRORLEVEL value from this bat file into an VBScript.
: I m always getting an zero errorlevel when i run the bat file from the
: script
: My code is below...
:
: BAT FILE
: ---------------------------------
: @echo off
::: do something that sets errorlevel 1
: REN fil fils
: echo %ERRORLEVEL%
: (this would return an 1 when run from dos prompt)
:
: VBScript
: -------------------------------------
: Dim fso, wShell, i
: Set wShell = CreateObject("WScript.Shell")
: Set fso = CreateObject("Scripting.FileSystemObject")
: i = wShell.Run ("C:\test1.bat", 1, True)
: WScript.Echo i
: (This should return 1, but returns only 0)
:
: Y is this happening, is there anything wrong with my logic
:
: Rajesh.N
:



Re: help needed by Alexander

Alexander
Mon Jul 17 05:21:36 CDT 2006

Walter Zackery schrieb:
> Your very last statement "echo %ERRORLEVEL%" runs successfully, so it
> returns an exit code of 0 to the script! If you remove this statement it
> will solve your problem.


AFAIK 'Echo', as most internal dos commands, doesn't change the existing
errorlevel. The prob is the most likely that the COMSPEC (cmd.exe) needs
to be switched in between to get to exitcode returned.

i = wShell.Run ("%comspec% /c C:\test1.bat", 1, True)

MfG,
Alex

> <gemini.rajesh@gmail.com> wrote in message
> news:1153117083.223438.215840@s13g2000cwa.googlegroups.com...
> : Im writing an bat file to rename an file with a new name, and i need to
> : get the ERRORLEVEL value from this bat file into an VBScript.
> : I m always getting an zero errorlevel when i run the bat file from the
> : script
> : My code is below...
> :
> : BAT FILE
> : ---------------------------------
> : @echo off
> ::: do something that sets errorlevel 1
> : REN fil fils
> : echo %ERRORLEVEL%
> : (this would return an 1 when run from dos prompt)
> :
> : VBScript
> : -------------------------------------
> : Dim fso, wShell, i
> : Set wShell = CreateObject("WScript.Shell")
> : Set fso = CreateObject("Scripting.FileSystemObject")
> : i = wShell.Run ("C:\test1.bat", 1, True)
> : WScript.Echo i
> : (This should return 1, but returns only 0)
> :
> : Y is this happening, is there anything wrong with my logic
> :
> : Rajesh.N
> :
>
>

Re: help needed by Jim

Jim
Mon Jul 17 07:41:20 CDT 2006

uhm... why not forget the silly bat file and simply so the whole thing in
vbs?



<gemini.rajesh@gmail.com> wrote in message
news:1153117083.223438.215840@s13g2000cwa.googlegroups.com...
> Im writing an bat file to rename an file with a new name, and i need to
> get the ERRORLEVEL value from this bat file into an VBScript.
> I m always getting an zero errorlevel when i run the bat file from the
> script
> My code is below...
>
> BAT FILE
> ---------------------------------
> @echo off
> :: do something that sets errorlevel 1
> REN fil fils
> echo %ERRORLEVEL%
> (this would return an 1 when run from dos prompt)
>
> VBScript
> -------------------------------------
> Dim fso, wShell, i
> Set wShell = CreateObject("WScript.Shell")
> Set fso = CreateObject("Scripting.FileSystemObject")
> i = wShell.Run ("C:\test1.bat", 1, True)
> WScript.Echo i
> (This should return 1, but returns only 0)
>
> Y is this happening, is there anything wrong with my logic
>
> Rajesh.N
>



Re: help needed by Walter

Walter
Mon Jul 17 09:05:06 CDT 2006

"Alexander Mueller" <millerax@hotmail.com> wrote in message
news:uWxgKrYqGHA.3732@TK2MSFTNGP04.phx.gbl...
: Walter Zackery schrieb:
: > Your very last statement "echo %ERRORLEVEL%" runs successfully, so it
: > returns an exit code of 0 to the script! If you remove this statement it
: > will solve your problem.
:
:
: AFAIK 'Echo', as most internal dos commands, doesn't change the existing
: errorlevel. The prob is the most likely that the COMSPEC (cmd.exe) needs
: to be switched in between to get to exitcode returned.
:
: i = wShell.Run ("%comspec% /c C:\test1.bat", 1, True)
:
: MfG,
: Alex
:

You are correct that ECHO doesn't change the errorlevel in the batch file,
but I can tell you from repeated testing that it does make a difference in
what is returned to the Run method. It also makes no difference whether you
invoke the command processor or not., the result is the same. It's very
peculiar behavior.

: > <gemini.rajesh@gmail.com> wrote in message
: > news:1153117083.223438.215840@s13g2000cwa.googlegroups.com...
: > : Im writing an bat file to rename an file with a new name, and i need
to
: > : get the ERRORLEVEL value from this bat file into an VBScript.
: > : I m always getting an zero errorlevel when i run the bat file from the
: > : script
: > : My code is below...
: > :
: > : BAT FILE
: > : ---------------------------------
: > : @echo off
: > ::: do something that sets errorlevel 1
: > : REN fil fils
: > : echo %ERRORLEVEL%
: > : (this would return an 1 when run from dos prompt)
: > :
: > : VBScript
: > : -------------------------------------
: > : Dim fso, wShell, i
: > : Set wShell = CreateObject("WScript.Shell")
: > : Set fso = CreateObject("Scripting.FileSystemObject")
: > : i = wShell.Run ("C:\test1.bat", 1, True)
: > : WScript.Echo i
: > : (This should return 1, but returns only 0)
: > :
: > : Y is this happening, is there anything wrong with my logic
: > :
: > : Rajesh.N
: > :
: >
: >



Re: help needed by Alexander

Alexander
Mon Jul 17 09:37:13 CDT 2006

Walter Zackery schrieb:

> "Alexander Mueller" <millerax@hotmail.com> wrote in message

> : Walter Zackery schrieb:
> : > Your very last statement "echo %ERRORLEVEL%" runs successfully, so it
> : > returns an exit code of 0 to the script! If you remove this statement it
> : > will solve your problem.
> :
> :
> : AFAIK 'Echo', as most internal dos commands, doesn't change the existing
> : errorlevel. The prob is the most likely that the COMSPEC (cmd.exe) needs
> : to be switched in between to get to exitcode returned.
> :
> : i = wShell.Run ("%comspec% /c C:\test1.bat", 1, True)
> :
> : MfG,
> : Alex
> :
>
> You are correct that ECHO doesn't change the errorlevel in the batch file,
> but I can tell you from repeated testing that it does make a difference in
> what is returned to the Run method. It also makes no difference whether you
> invoke the command processor or not., the result is the same. It's very
> peculiar behavior.
>

You're probably right, I didn't test it - I only thought I to remember
this detail or something of that kind from the time when I used to
launch cmd-scripts from VBS-scripts myself, which is quite some time
ago.

MfG,
Alex


Re: help needed by Michael

Michael
Mon Jul 17 21:47:58 CDT 2006

gemini.rajesh@gmail.com wrote:
> Im writing an bat file to rename an file with a new name, and i need
> to get the ERRORLEVEL value from this bat file into an VBScript.
> I m always getting an zero errorlevel when i run the bat file from the
> script
> My code is below...
>
> BAT FILE
> ---------------------------------
> @echo off
>>> do something that sets errorlevel 1
> REN fil fils
> echo %ERRORLEVEL%

REM add an explicit exit statement...

exit %ERRORLEVEL%

> (this would return an 1 when run from dos prompt)
>
> VBScript
> -------------------------------------
> Dim fso, wShell, i
> Set wShell = CreateObject("WScript.Shell")
> Set fso = CreateObject("Scripting.FileSystemObject")
> i = wShell.Run ("C:\test1.bat", 1, True)
> WScript.Echo i
> (This should return 1, but returns only 0)
>
> Y is this happening, is there anything wrong with my logic
>
> Rajesh.N

--
Michael Harris
Microsoft MVP Scripting



Re: help needed by gemini

gemini
Tue Jul 18 01:31:08 CDT 2006

Halo,

Thanx for ur help, my problem was solved when i removed the last line
of my BAT file

Regards,
Rajesh.N