'Capturing' Error Messages 
Author Message
 'Capturing' Error Messages

I am calling a program from a .vbs script and would like to log any
error message it generates on exit. My script looks like this at the
moment:

Quote:
>shell.Run "C:\Lalix\Client\lxCliTest.exe" & lxcli, 2, True
>LogEvent("End Collection from " &aKeys(i) & " " & Err.Number & " " & Err.Description)

With logevent being a separate function that writes to a log file.

At the moment, nothing is appearing in the error code or description
bit. Am I misunderstanding this?

Thanks,

Stefan



Tue, 01 Jul 2003 16:57:53 GMT  
 'Capturing' Error Messages

Quote:

> I am calling a program from a .vbs script and would like to log any
> error message it generates on exit. My script looks like this at the
> moment:

> >shell.Run "C:\Lalix\Client\lxCliTest.exe" & lxcli, 2, True
> >LogEvent("End Collection from " &aKeys(i) & " " & Err.Number & " " & Err.Description)

> With logevent being a separate function that writes to a log file.

> At the moment, nothing is appearing in the error code or description
> bit. Am I misunderstanding this?

> Thanks,

> Stefan


Yes, you are "misunderstanding this".  The underlying program's
errorlevel, if any, is reported back as a result from the Run, not
through the Err object (unless Run fails, which is reported via Err).
Read the documentation:

Full download of WSH documentation -
  http://msdn.microsoft.com/scripting/windowshost/wshdoc.exe

You want something like ...

  sCmd = "C:\Lalix\Client\lxCliTest.exe" & lxcli
  ErrReturn = shell.Run(sCmd, 2, True)
  LogEvent("End Collection from " & aKeys(i) & " " & ErrReturn)

There will be no description of any error available.  Console (DOS)
application error messages can be collected under Win NT, if you run the
application under the command processor and redirect the StdErr to a
file.  But, that's fairly complex and doesn't work for most application
under Win 95/98.  I think a better way is to map the possible ErrReturn
values into an array of description of those errors in your script, that
is ...

  aErrDescriptions(0) = "Alls well that ends well"
  aErrDescriptions(1) = "Error number 1 was returned"
  aErrDescriptions(2) = "Whoa, error number 2 - that's bad"
 ...

Then you can log those ...

  LogEvent("End Collection from " & aKeys(i) & " " & ErrReturn & _
           aErrDescriptions(ErrReturn))

Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/



Tue, 01 Jul 2003 23:48:38 GMT  
 'Capturing' Error Messages
Hi there,

The Err Object works only for the script executing. It does not capture
errors from external programs.
You could use one of two options:
1. Capture the return of the program being run:
ErrorLevel = Shell.Run program, 2, TRUE

2. Capture the errorlevel environment variable
ErrorLevel = wScript.ExpandEnironmentStrings("%ERRORLEVEL%")

Either should work.
Luey


Quote:
> I am calling a program from a .vbs script and would like to log any
> error message it generates on exit. My script looks like this at the
> moment:

> >shell.Run "C:\Lalix\Client\lxCliTest.exe" & lxcli, 2, True
> >LogEvent("End Collection from " &aKeys(i) & " " & Err.Number & " " &
Err.Description)

> With logevent being a separate function that writes to a log file.

> At the moment, nothing is appearing in the error code or description
> bit. Am I misunderstanding this?

> Thanks,

> Stefan




Wed, 02 Jul 2003 01:01:59 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. 'Capturing' Error Messages

2. CDO.Message.1 error '8007000e'

3. HELP needed with 'eoclip' error message

4. HELP vbs capture of 'backspace'

5. Capture result/output from 'run'-command

6. Runtime error ''800a01b6''

7. Item won't delete, but I got rid of my error message

8. error 'ASP 0115' Unexpected error

9. 'Script Running' Message

10. Run-time error '429': ActiveX component can't create object

11. How to capture Error and print a decent message

12. Capture Error Message to Text file

 

 
Powered by phpBB® Forum Software