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?

Re: Return code=0 even if runtime error by Thorsten

Thorsten
Mon Nov 29 06:34:12 CST 2004

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?



Re: Return code=0 even if runtime error by McKirahan

McKirahan
Mon Nov 29 06:44:19 CST 2004

"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?



Re: Return code=0 even if runtime error by pka

pka
Mon Nov 29 07:09:10 CST 2004



"McKirahan" wrote:

> "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?
> > > The script is run inside a .bat and I check the ERRORLEVEL

> Also, how about seeing if the file exists before trying to copy it?
> > > My question is more general. If I have an unhandled error in a script I want the return code be other than 0 like in perl, ksh or other script languages.
>
>

Re: Return code=0 even if runtime error by tlavedas

tlavedas
Mon Nov 29 07:21:02 CST 2004

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/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en

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

"PKA" wrote:

>
>
> "McKirahan" wrote:
>
> > "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?
> > > > The script is run inside a .bat and I check the ERRORLEVEL
>
> > Also, how about seeing if the file exists before trying to copy it?
> > > > My question is more general. If I have an unhandled error in a script I want the return code be other than 0 like in perl, ksh or other script languages.
> >
> >

Re: Return code=0 even if runtime error by McKirahan

McKirahan
Mon Nov 29 07:23:28 CST 2004

"PKA" <pka@bnpparibas.com> wrote in message
news:09E6430C-29DE-4D36-873B-9B3AD9C5D6ED@microsoft.com...
>
>
> "McKirahan" wrote:
>
> > "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?
> > > > The script is run inside a .bat and I check the ERRORLEVEL
>
> > Also, how about seeing if the file exists before trying to copy it?
> > > > My question is more general. If I have an unhandled error in a
script I want the return code be other than 0 like in perl, ksh or other
script languages.
> >
> >

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



Re: Return code=0 even if runtime error by Michael

Michael
Mon Nov 29 20:05:53 CST 2004

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