Jump to content

Recommended Posts

Posted

I have a strange situation in running a script: usually the RunWait() runs AOK but occasionally hovering on the Autoit icon in the notification area shows that the script is waiting for the RunWait line to complete.

I would like to add to the script the ability to advise the user that the script is stuck at this line of code if it is stuck for more than 2 seconds.

I have been experimenting with the _Timer UDFs, but I am yet to figure out a solution.

Does anyone have any ideas?

 

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Posted (edited)

You could do something like this to check if the process hasn't closed within your parameters, and act accordingly.

$PID = Run("Notepad.exe")
$Timer = TimerInit()
Do
    If Not ProcessExists($PID) Then ExitLoop
Until TimerDiff($Timer) > 2000
If ProcessExists($PID) Then
    MsgBox(0, "Error", "Process hasn't closed yet")
Else
    MsgBox(0, "OK", "Process closed within 2 seconds")
EndIf

 

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted (edited)

Thank you for this simple, elegant, solution.

However, I failed to mention that my script uses the exit code of the program it runs, so switching from RunWait() to Run() would lose me this info. If there a way of getting the exit code if the program exits within 2 seconds and telling the user that the program failed to complete within 2 seconds?

Edited by c.haslam
Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Posted

Have a look at the example in the help file for _WinAPI_GetExitCodeProcess.  This shows you how to get the exit code from the PID using _WinAPI_OpenProcess, _WinAPI_GetExitCodeProcess, and _WinAPI_CloseHandle.  

 

Adam

 

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
  • Recently Browsing   0 members

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