For Programmers: Free Programming Magazines  


Home > Archive > VBScript > November 2004 > Return code=0 even if runtime error









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Return code=0 even if runtime error
PKA

2004-11-29, 3:59 pm

The code:
File.Copy(FichierCible)

Produce this error:
C:\win32app\exploit\HFTrader-PDL\HFTPDL.vbs(89, 4) Microsoft VBScript
runtime error: Path not found

But the return code of the script is 0.
I can handle this specific error with the "on error" clause but how can I
do to exit with a return code <> 0 when i have an unhandled error?
Thorsten Helfer

2004-11-29, 3:59 pm

Hi PKA,
(btw: funny name - ever heart about using real names?)

Something like that?

Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
Err.Clear
On Error Resume Next
FSO.CopyFile "c:\boot.ini", "c:\NonExistingFolder\"
strError = Err.Number
On Error GoTo 0
If strError <> 0 Then {DoWhateverYouWant}

hth,
Thorsten


"PKA" <pka@bnpparibas.com> schrieb im Newsbeitrag
news:A8215069-5803-4D1A-B435-6EF908D52612@microsoft.com...
> The code:
> File.Copy(FichierCible)
>
> Produce this error:
> C:\win32app\exploit\HFTrader-PDL\HFTPDL.vbs(89, 4) Microsoft VBScript
> runtime error: Path not found
>
> But the return code of the script is 0.
> I can handle this specific error with the "on error" clause but how can I
> do to exit with a return code <> 0 when i have an unhandled error?



McKirahan

2004-11-29, 3:59 pm

"PKA" <pka@bnpparibas.com> wrote in message
news:A8215069-5803-4D1A-B435-6EF908D52612@microsoft.com...
> The code:
> File.Copy(FichierCible)
>
> Produce this error:
> C:\win32app\exploit\HFTrader-PDL\HFTPDL.vbs(89, 4) Microsoft VBScript
> runtime error: Path not found
>
> But the return code of the script is 0.
> I can handle this specific error with the "on error" clause but how can I
> do to exit with a return code <> 0 when i have an unhandled error?


How are you getting a return code?

Also, how about seeing if the file exists before trying to copy it?


PKA

2004-11-29, 3:59 pm



"McKirahan" wrote:

> "PKA" <pka@bnpparibas.com> wrote in message
> news:A8215069-5803-4D1A-B435-6EF908D52612@microsoft.com...
>
> How are you getting a return code?
[color=darkred]
> Also, how about seeing if the file exists before trying to copy it?
>
>

Tom Lavedas

2004-11-29, 3:59 pm

You want a 'Wscript.Quit ExitCode' statement. See the documentation for the
Quit method.

WSH 5.6 documentation download (URL all one line)
http://www.microsoft.com/downloads/...&displaylang=en

Tom Lavedas
===========

"PKA" wrote:
[color=darkred]
>
>
> "McKirahan" wrote:
>
>
McKirahan

2004-11-29, 3:59 pm

"PKA" <pka@bnpparibas.com> wrote in message
news:09E6430C-29DE-4D36-873B-9B3AD9C5D6ED@microsoft.com...[color=darkred]
>
>
> "McKirahan" wrote:
>
can I[color=darkred]
>
script I want the return code be other than 0 like in perl, ksh or other
script languages.[color=darkred]

Could you post your BAT file code so we can see what you're doing?


Michael Harris \(MVP\)

2004-11-30, 3:56 am

PKA wrote:
> The code:
> File.Copy(FichierCible)
>
> Produce this error:
> C:\win32app\exploit\HFTrader-PDL\HFTPDL.vbs(89, 4) Microsoft VBScript
> runtime error: Path not found
>
> But the return code of the script is 0.
> I can handle this specific error with the "on error" clause but how
> can I do to exit with a return code <> 0 when i have an unhandled
> error?



This is a known bug in WSH 5.6. Unhandled runtime errors do not cause the
hosts (wscript/cscript.exe) to exit with a non-zero exit code when executing
*.vbs or *.js files.

A known workaround to is to use the *.wsf file format, in which case an
unhandled runtime error causes the hosts to exit with an exit code of 1.


--
Michael Harris
Microsoft MVP Scripting


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com