VelvetElvis Posted November 8, 2011 Share Posted November 8, 2011 (edited) 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? Edited November 8, 2011 by VelvetElvis Link to comment Share on other sites More sharing options...
VelvetElvis Posted November 10, 2011 Author Share Posted November 10, 2011 <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 More sharing options...
Moderators JLogan3o13 Posted November 10, 2011 Moderators Share Posted November 10, 2011 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 More sharing options...
AdmiralAlkex Posted November 10, 2011 Share Posted November 10, 2011 (edited) 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 November 10, 2011 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
VelvetElvis Posted November 11, 2011 Author Share Posted November 11, 2011 (edited) 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 November 11, 2011 by VelvetElvis Link to comment Share on other sites More sharing options...
VelvetElvis Posted November 11, 2011 Author Share Posted November 11, 2011 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 More sharing options...
VelvetElvis Posted November 11, 2011 Author Share Posted November 11, 2011 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. 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 More sharing options...
VelvetElvis Posted November 13, 2011 Author Share Posted November 13, 2011 <bump> Sorry to be persistent and/or dense. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now