DefinedV Posted March 10, 2010 Share Posted March 10, 2010 I would like to keep track of program runtime on exit, how would I go about doing so in AutoIt? -Thanks Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted March 10, 2010 Share Posted March 10, 2010 Hi and Welcome to the forum! Do you mean how long the script has been running? Maybe something like this fits: #include <Date.au3> Global $iStartTime = _Now() OnAutoItExitRegister("_OnExit") MsgBox(0, "", "Wait a while and close me") Func _OnExit() ConsoleWrite(_DateDiff("s", $iStartTime, _Now()) & @CRLF) EndFunc The function registered with OnAutoItExitRegister() will run when the script gracefully exist. If you want to get the time even if it get closed from "task manager" and such tools it would be more advanced. .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...
DefinedV Posted March 10, 2010 Author Share Posted March 10, 2010 Hi and Welcome to the forum! Do you mean how long the script has been running? Maybe something like this fits: #include <Date.au3> Global $iStartTime = _Now() OnAutoItExitRegister("_OnExit") MsgBox(0, "", "Wait a while and close me") Func _OnExit() ConsoleWrite(_DateDiff("s", $iStartTime, _Now()) & @CRLF) EndFunc The function registered with OnAutoItExitRegister() will run when the script gracefully exist. If you want to get the time even if it get closed from "task manager" and such tools it would be more advanced. Thanks, that's exactly what I was looking for. Was hoping there was a solution better then converting the time from differences in hour/minute/second, and this seems much more convenient. Although, is there a way to display it with a msgbox? I tried but it always yielded a value of 0. My code is below. Func _OnExit() $end = (_DateDiff("s", $iStartTime, _Now()) & @CRLF) msgbox(0,"",$end) EndFunc -Thanks Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted March 10, 2010 Share Posted March 10, 2010 If you didn't just let it run for 0 seconds I don't know. Take this for example, the msgbox says 3. #include <Date.au3> Global $iStartTime = _Now() OnAutoItExitRegister("_OnExit") Sleep(3000) ;Do nothing for 3 seconds Func _OnExit() $end = _DateDiff("s", $iStartTime, _Now()) ;"()" not really needed and @CRLF seemed pointless there. msgbox(0,"",$end) EndFunc .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...
somdcomputerguy Posted March 10, 2010 Share Posted March 10, 2010 (edited) I'm still running with 3.3.4.0, not the most current version, and _DateDiff seems not to function properly with _Now(), but it does work correctly with _NowCalc(). Edit: however it could be my PCs date/time format is incorrect format for _DateDiff.. Another Edit: ConsoleWrite(_Now() & @LF) ConsoleWrite(_NowCalc() & @LF) Returns 3/9/2010 9:31:43 PM 2010/03/09 21:31:43 So it's not a version info.. Edited March 10, 2010 by snowmaker - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
DefinedV Posted March 10, 2010 Author Share Posted March 10, 2010 (edited) Ahh thanks guys. It's working now with: #include <Date.au3> Global $iStartTime = _NowCalc() OnAutoItExitRegister("_OnExit") Sleep(3000) ;Do nothing for 3 seconds Func _OnExit() $end = _DateDiff("s", $iStartTime, _NowCalc()) ;"()" not really needed and @CRLF seemed pointless there. msgbox(0,"",$end) EndFunc Ahh is there any way to convert the output to something similar to HH:MM:SS without writing my own function? Edited March 10, 2010 by DefinedV 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