DigDeep Posted September 7, 2018 Posted September 7, 2018 Hi, My code works fine 95% times. 5% case I have seen if the criteria does not match, it goes on loop. Can someone help to get this adjusted. I am currently using as: Run(Command-Line) Do Sleep(1000) Until Not ProcessExists("PID") And FileExists("FilePath") Sleep(30000) I was thinking if I can put a check which will tell me if: 1. Process has closed and file exists then it went good. 2. Process has closed but file does not exists then it has failed. The only issue here is that I am not sure of the exact time the application takes to install. Sometimes it happens within 5 minutes and sometimes even takes 15-20 minutes. But logically, not more than that. Run(Command-Line) Do Sleep(1000) Until ProcessCheck() Sleep(30000) Func ProcessCheck() If Not ProcessExists("PID1") And ProcessExists("PID2") And FileExists("FilePath") Then MsgBox(0, '', 'Application installed successfully.') ElseIf Not ProcessExists("PID1") And Not ProcessExists("PID2") And Not FileExists("FilePath") Then MsgBox(0, '', 'Application Failed to install.') EndIf EndFunc ;==>ProcessCheck
FrancescoDiMuro Posted September 7, 2018 Posted September 7, 2018 @DigDeep In order to use the code you wrote above, you should set an instruction like Return False or Return True. If you could provide a bit more information, I think we can help you more Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Developers Jos Posted September 7, 2018 Developers Posted September 7, 2018 Just now, FrancescoDiMuro said: In order to use the code you wrote above, you should set an instruction like Return False or Return True. He actually does do that. @DigDeep, Your test is for: (Not ProcessExists("PID") ) And (FileExists("FilePath")). Is that what you wanted? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
DigDeep Posted September 7, 2018 Author Posted September 7, 2018 @Jos Correct. to re-emphasize here. The 1st code I have provided is the one I am using now which is running all good except for some scenarios where both the Process had closed and File still did not exist and the code was going on running.......................... Will it be possible for the Do Until can check for every 10 minutes if the Process has closed and file is existing for 3 times which will be total of 30 minutes. During any of the 3 checks if it find Process Closed and File exists then Passed Else will state as Failed and Stop / Return.
aa2zz6 Posted September 7, 2018 Posted September 7, 2018 I dunno if you'd want to incorporate this piece of code below @DigDeep but this scan the C directory until it finds the SOFTWARE.exe and makes a INI file with the full path inside the same folder with the script. If the INI file is created than it was a successfully found in the C:\ drive. Hopefully you find this helpful and if you don't let us know p.s. I've never done an installation script so there maybe a better method. Scan C:\ drive expandcollapse popup#include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> #include <Date.au3> ; Global Variables Global $Results = @ScriptDir & "\" Global Enum $RFS_ERROR_RUN = 2 Global Const $g_sFileName = 'SOFTWARE.exe', _ ; << Insert Software .EXE to search in C:\ directories $g_sFilePath = 'C:\', _ $g_sFileMsg = 'file : "%s"\n(sub-)folder : "%s"\nlocated at : "%s"\n' while 1 _RunFromSubfolder($g_sFileName, $g_sFilePath) sleep(10000) WEnd Func _RunFromSubfolder(Const $sFile1, Const $sFolder1) Local $sMessage = '' Local $iError = 0, _ $iExtd = 0, _ $iPID = 0 Local Const $aItems = _FileListToArrayRec($sFolder1, $sFile1, $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) If @error Then $iError = @error $iExtd = @extended Else $sMessage = StringFormat($g_sFileMsg, $sFile1, $sFolder1, $aItems[1]) $iExtd = $aItems[0] ;$iPID = Run($aItems[1]) $Filepath = $aItems[1] FileWrite($Results & "Software" & ".ini", _ "[Software]" & @CRLF & _ "Dir=" & $Filepath & @CRLF) ; write to file here ;$iPID = Run($Filepath) If @error Then $iError = $RFS_ERROR_RUN $iExtd = @error EndIf ConsoleWrite($sMessage) EndIf Return SetError($iError, $iExtd, $iPID) EndFunc ;==>_RunFromSubfolder Timer Example $stamp = TimerInit() While 1 ;MsgBox(0,"",Int(TimerDiff($stamp) / 1000) / 60 & " minutes" & @CRLF & Int(TimerDiff($stamp) / 1000) & " seconds") ;If last time stamp was greater than or equal to 10 minutes If ((TimerDiff($stamp) / 1000) / 60) >= 10 Then ;COMMANDS HERE $stamp = TimerInit() EndIf WEnd
therks Posted September 8, 2018 Posted September 8, 2018 (edited) @DigDeep Are you doing something in the Do/Until loop besides sleeping? If not, could you just use ProcessWaitClose? Run(Command-Line) ProcessWaitClose("PID") If FileExists("FilePath") Then MsgBox(0, '', 'Success! :)') Else MsgBox(16, '', 'Failure :(') EndIf *Edit: Why do my code tags always start out discoloured? Edited September 8, 2018 by therks My AutoIt Stuff | My Github
markyrocks Posted September 8, 2018 Posted September 8, 2018 (edited) If you get to the scenario where the application fails, after the msgbox put exit if that's the end if it fails. Or put some type of return Do Until processcheck() = false If everything fails ect then Msgbox(fail) Return false You could also make it exit by making it exit loop under true or false and depending on what you want to happen after have more than one scenario by saving the return value in a variable. Do $bool=processcheck() Until $bool=true or false The way you have it process check returns nothing so it has no value so the until processcheck() ... has no end. You could also just put the contents of the function in the do until loop and just add an "exitloop" after the fail msgbox. Edited September 8, 2018 by markyrocks Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning"
markyrocks Posted September 8, 2018 Posted September 8, 2018 On 9/7/2018 at 2:58 AM, DigDeep said: Run(Command-Line) Do Sleep(1000) Until Not ProcessExists("PID") And FileExists("FilePath") Sleep(30000) This doesn't take into account the file not existing. I like the idea of having these different scenarios in the function and just returning different values to account for them. Like if everything needs to continue return 0 if it succeeds return true if it fails return false. Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning"
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