RunWait timeout? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
diaewad

RunWait timeout?

06 Feb 2015, 09:49

I'm trying to figure out a timeout function for RunWait. I checked the help file but couldn't quite figure it out. I have a simple code to grab the ip address off and excel spreadsheet and ftp to it, but after I use it once or twice, it just stops working. I'm guessing it's because of a timeout problem, but I don't know for certain. Here's my code:

Code: Select all

#F::
Send ^c
Sleep, 150
RunWait, %comspec% /c ftp %clipboard%
Return
If anyone knows of another reason why it happens, please let me know. Thanks!
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: RunWait timeout?

06 Feb 2015, 12:48

It seems likely that Excel is loosing focus and or the cell contents are not being copied to the clipboard.
You could use COM to create a more reliable means of getting the ip address.
Something like:

Code: Select all

book := A_ScriptDir "\book1.xls" ; change this to the path of your excel file
cell = A1 			  ; change this to the cell containing the IP address
xlObj := ComObjGet( book )
ip := xlObj.Sheets( 1 ).Range( cell ).Value

RunWait, %comspec% /c ftp %ip%
;..............
That said, this should kill the FTP executed by RunWait after 3 seconds
( make sure you're running AHk with Admin privileges on! )

Code: Select all

#F::
Send ^c
Sleep, 150
SetTimer, Kill_FTP, -3000 ; change 3000 to in/decrease the amount of time to wait.
RunWait, %comspec% /c ftp %clipboard%,, UseErrorLevel, ftpPID

; place the rest of your script here

Return

Kill_FTP:
If ( ErrorLevel != 0 )
    WinKill % "ahk_pid " ftpPID
Return
You could also check the clipboard to make sure it has an IP address on it before trying the RunWait

Code: Select all

#F::
Send ^c
Sleep, 150
if !( clipboard ~= "^(\d{1,3}\.){3}\d{1,3}" )
{
    Msgbox, 0x10, Whoops!, There is no IP Address on the clipboard! Please try again.
    Return
}

SetTimer, Kill_FTP, -3000 ; change 3000 to in/decrease the amount of time to wait.
RunWait, %comspec% /c ftp %clipboard%,, UseErrorLevel, ftpPID

; place the rest of your script here

Return

Kill_FTP:
If ( ErrorLevel != 0 )
    WinKill % "ahk_pid " ftpPID
Return
just some ideas to try..
diaewad

Re: RunWait timeout?

06 Feb 2015, 14:06

That all looks awesome. I have to use this for my spreadsheet with over 600 entries that I then have to update, so COM wouldn't work here, but that will help me in a MASSIVE way in the future, so I thank you greatly for that!!
I know it's grabbing the data, because the Excel cell always blinks once it transfers to the clipboard, plus even if it was empty, it would just bring up the command prompt with an ftp> prompt (this has happened to me already)

I will certainly try the timeout.

Thank you so much for your help!
A_User
Posts: 36
Joined: 21 Aug 2017, 01:15

Re: RunWait timeout?  Topic is solved

20 Nov 2017, 11:29

Another approach I found is to use `Process, WaitClose`.

Code: Select all

#SingleInstance, Force
#Persistent

new RunWait( 3 ).run( "notepad" )
msgbox done
Return

class RunWait {

    iTimeout := 10

    __New( iTimeout=10 ) {
        this.iTimeout := iTimeout
    }

    run( sCommand ) {
    
        Run, % sCommand,, UseErrorLevel, _iPID        
        _func   := ObjBindMethod( this, "closeProcess", _iPID )
        SetTimer, % _func, % this.iTimeout ? this.iTimeout * -1000 : -1
        Process, WaitClose, % _iPID, % this.iTimeOut
        
    }
        
    closeProcess( iPID ) {
        Process, Close, % iPID
    }

}
degarb
Posts: 37
Joined: 28 Mar 2020, 11:55

Re: RunWait timeout?

18 Jul 2021, 09:20

A_User wrote:
20 Nov 2017, 11:29
Another approach I found is to use `Process, WaitClose`.

Code: Select all

#SingleInstance, Force
#Persistent

new RunWait( 3 ).run( "notepad" )
msgbox done
Return

class RunWait {

    iTimeout := 10

    __New( iTimeout=10 ) {
        this.iTimeout := iTimeout
    }

    run( sCommand ) {
    
        Run, % sCommand,, UseErrorLevel, _iPID        
        _func   := ObjBindMethod( this, "closeProcess", _iPID )
        SetTimer, % _func, % this.iTimeout ? this.iTimeout * -1000 : -1
        Process, WaitClose, % _iPID, % this.iTimeOut
        
    }
        
    closeProcess( iPID ) {
        Process, Close, % iPID
    }

}

It would take me 3 weeks to figure out what class means. The documents make it even more confusing. (I am really disappointed in the chem documents, after seeing them in 2005 to now. They are becoming incomprehensible to anyone who is not a dedicated professional.)


The docs say, "Classes [v1.1.00+]
At its root, a "class" is a set or category of things having some property or attribute in common. Since a base or prototype object defines properties and behaviour for set of objects, it can also be called a class object. For convenience, base objects can be defined using the "class" keyword as shown below:"

The above is meaningless, and I don't see its clear comprehensible example.
gregster
Posts: 8999
Joined: 30 Sep 2013, 06:48

Re: RunWait timeout?

18 Jul 2021, 09:30

degarb wrote:
18 Jul 2021, 09:20
(I am really disappointed in the chem documents, after seeing them in 2005 to now. They are becoming incomprehensible to anyone who is not a dedicated professional.)
The 2005 AHK version is not comparable to today's, by far - there are so many more things you can do nowadays.

That said, you can still find old 1.0.x versions and use them - if you prefer - but don't expect explicit support for them from these forums - as most people moved on long ago.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Joey5, TAC109 and 171 guests