Jump to content

Handling a ShellExecuteWait() error


Recommended Posts

I'm using ShellExecuteWait() to call an external command line app that has a ton of .dll and other files. I'm trying to capture any number of errors that occur anywhere in the process. I've attached an example below. These stop my app dead

I've tried an error handler routine I found in the help file, using

Global $g_eventerror = 0    ; to be checked to know if com error occurs. Must be reset after handling.
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")    ; Initialize a COM error handler
ShellExecuteWait ( @ScriptDir  & "mogrify.exe", "-resize 640x480 -quality 80 ..*.jpg")

If $g_eventerror then
    $g_eventerror = 0
  Msgbox (0,"AutoItCOM test","Test passed: We got an error number: " & @error)
Else
  Msgbox (0,"AutoItCOM test","Test failed!")
Endif
Exit

Func MyErrFunc()
  ;etc....

Problem is, it isn't triggered until after I manually close the Windows error message.

Is there any way to trap these, so I can log the culprit and not have my script doesn't die a lonely painful death when it goes into use? :D

post-40658-0-33650300-1320786039_thumb.j

Edited by VelvetElvis
Link to comment
Share on other sites

<Bump>

Anyone have any thoughts?

I've added a routine - AdlibRegister("CatchErrorMsg")

which catches *some* of the possible errors that occur during ShellExecuteWait(), but there's still one error dialog (when ShellExecuteWait() can't find the file it executes) that causes my script to hang.

Yet if I run a separate test app that looks for the error dialog, it finds it and closes it. But I can't get my app to do this.

As a workaround, I validate that the file exists, but there's so many .dlls that this app uses (ImageMagick) that it's impractical to test for them all, and no guarantee that some other unspecified error dialog won't show.

Anyone know of an error handler to use with ShellExecuteWait() that's more bulletproof? I'm a putz when it comes to this stuff.

Link to comment
Share on other sites

  • Moderators

Not sure about a handler specific to ShellExecuteWait(), but if it is throwing Windows errors, could you query the Event Viewer for either the Error Code or the Description? The EventLog udf provides a number of options that may help.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Yet if I run a separate test app that looks for the error dialog, it finds it and closes it. But I can't get my app to do this.

You are using ShellExecuteWait() so logic dictates the script is waiting for the app to end. Try ShellExecute() instead. Edited by AdmiralAlkex
Link to comment
Share on other sites

Not sure about a handler specific to ShellExecuteWait(), but if it is throwing Windows errors, could you query the Event Viewer for either the Error Code or the Description? The EventLog udf provides a number of options that may help.

Thank you! I'm not familiar with this UDF. I'll have to check it out. The only problem is there are a myriad of different possible errors, due to the huge amount of dependencies of the executable I'm calling.

Edited by VelvetElvis
Link to comment
Share on other sites

You are using ShellExecuteWait() so logic dictates the script is waiting for the app to end. Try ShellExecute() instead.

Thanks.

I was under the impression, mistaken, I guess, that AdlibRegister() would always fire regardless of what the rest of the script was doing, but that doesn't appear to be the case.

If I use ShellExecute, how can I tell when the external app has finished?

Link to comment
Share on other sites

OK, I tried switching from ShellExecuteWait() to ShellExecute(). Here's some pretty generic test code.

The script hangs at ShellExecute() and doesn't close the error message. :D

Can anyone tell me why this is hanging? I realize I can test for the file before running, but I want to know why I can't close this Windows error message. I need to be able to deal with all errors.

#include <File.au3>
Opt("WinTitleMatchMode", 2) ; Should catch "missingfile.exe" anywhere in the window title
AdlibRegister("CatchErrorMsg")

ShellExecute(@ScriptDir & "\missingfile.exe", "", "", Default, @SW_HIDE)
MsgBox(0, "", "Done")
Exit
; ***********************************************************
Func CatchErrorMsg() ; Try to trap errors occurring during ShellExecuteWait()
If WinExists("missingfile.exe") Then ; This window exists!
  WinActivate("missingfile.exe")
  MsgBox(0, "", WinGetText("missingfile.exe"))
  Send("{ENTER}")
  Exit
EndIf
EndFunc   ;==>CatchErrorMsg
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...