LurchMan Posted January 15, 2009 Share Posted January 15, 2009 (edited) Hey All - When I run this, It will go into the Correct Func, but It won't correctly test for if the process exists. Thanks in advance for any help. expandcollapse popupOpt("TrayIconDebug" , 1) $01DlyRpt1 = @ScriptDir & "\01 Dly Prd Rpt1 - After Region v1.3.exe" $06ProdRpt = @ScriptDir & "\06 Prod Rpts - After Region v1.3.exe" $ProcDlyRpt1 = "01 Dly Prd Rpt1 - After Region v1.3.exe" $Proc06Prod = "06 Prod Rpts - After Region v1.3.exe" Global $sFile = @Scriptdir & "\Bin\Script Config.ini" Global $aFinished[2][3] = [["01 Dly Prd Rpt1", "DlyRpt1" , $01DlyRpt1], _ ["06 Prod Rpts", "ProdRpts" , $06ProdRpt]] Global $n , $j Search () Func Search () While 1 For $n = 0 to UBound($aFinished, 1) - 1 $Read = IniRead ($sFile , $aFinished[$n][0] , "Finished" , 0) If $Read = 1 Then Call ($aFinished[$n][1]) Sleep (2000) Next Wend EndFunc Func DlyRpt1 () MsgBox (0, "" , "dly rpts func") $proc = ProcessExists($ProcDlyRpt1) If $proc > 0 Then MsgBox (0, "" , "dly prd rpt1 proc exists") Search () Else Run ($aFinished[$n][2]) EndIf EndFunc Func ProdRpts () MsgBox (0, "" , "06 prod rpts func") $Proc = ProcessExists($Proc06Prod) If $Proc <> 0 Then MsgBox (0, "" , "06 prod rpts exists") Search () Else Run ($aFinished[$n][2]) EndIf EndFunc Edited January 16, 2009 by LurchMan Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end. Link to comment Share on other sites More sharing options...
SpookMeister Posted January 15, 2009 Share Posted January 15, 2009 It seams to me that you are getting into infinite loops. I'm having difficulty following the flow of your program, because we do not have an example of the .ini you are referencing. Also since both of those later functions are nearly identical you could easily just make one function that you pass the appropriate information to... like: Func Reports ($process_to_check,$executable_to_run) MsgBox (0, "" , "looking for " & $process_to_check) $Proc = ProcessExists($process_to_check) If $Proc <> 0 Then MsgBox (0, "" , "06 prod rpts exists") ;Search () Else Run ($executable_to_run) EndIf EndFunc [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 15, 2009 Share Posted January 15, 2009 Are you sure those strings really match the process names (in Task Manager), and the processes are there at the time? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
LurchMan Posted January 15, 2009 Author Share Posted January 15, 2009 It seams to me that you are getting into infinite loops. I'm having difficulty following the flow of your program, because we do not have an example of the .ini you are referencing. [06 Prod Rpts] HasRun=0 Finished=0 Thats the chunk of the INI file that its reading. Basically when one script finishes it sets the finished key to 1, then this one im working on right now will read it an when the finished key = 1 it will start the next script. I know its an infinite loop thats kinda what i was trying for. I'm basically right now, just trying to get it to recognize it and run the next script in line. I'm basically creating an automatic scheduler, and I can't use windows scheduling because when I'm finished it will run on several computers across a network. Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end. Link to comment Share on other sites More sharing options...
LurchMan Posted January 15, 2009 Author Share Posted January 15, 2009 (edited) Are you sure those strings really match the process names (in Task Manager), and the processes are there at the time? Thats the thing - If its not running I want it to run it, and I know for sure they aren't running when i run this script.Edit: I confirmed that the strings are an exact match to the proccess names Edited January 15, 2009 by LurchMan Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end. Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 16, 2009 Share Posted January 16, 2009 Thats the thing - If its not running I want it to run it, and I know for sure they aren't running when i run this script. Edit: I confirmed that the strings are an exact match to the proccess names Try it more like this: expandcollapse popupOpt("TrayIconDebug", 1) Global $01DlyRpt1 = @ScriptDir & "\01 Dly Prd Rpt1 - After Region v1.3.exe" Global $06ProdRpt = @ScriptDir & "\06 Prod Rpts - After Region v1.3.exe" Global $ProcDlyRpt1 = "01 Dly Prd Rpt1 - After Region v1.3.exe" Global $Proc06Prod = "06 Prod Rpts - After Region v1.3.exe" Global $sFile = @ScriptDir & "\Bin\Script Config.ini" Global $aFinished[2][3] = [["01 Dly Prd Rpt1", "DlyRpt1", $01DlyRpt1], _ ["06 Prod Rpts", "ProdRpts", $06ProdRpt]] Global $n While 1 For $n = 0 To UBound($aFinished, 1) - 1 $Read = IniRead($sFile, $aFinished[$n][0], "Finished", 0) If $Read = "1" Then Call($aFinished[$n][1]); 1 = finished, do post-processing Sleep(2000) Next WEnd Func DlyRpt1() MsgBox(0, "", "dly rpts func") $proc = ProcessExists($ProcDlyRpt1) If $proc > 0 Then MsgBox(0, "", "dly prd rpt1 proc exists") Else Run($aFinished[$n][2]) EndIf EndFunc ;==>DlyRpt1 Func ProdRpts() MsgBox(0, "", "06 prod rpts func") $proc = ProcessExists($Proc06Prod) If $proc <> 0 Then MsgBox(0, "", "06 prod rpts exists") Else Run($aFinished[$n][2]) EndIf EndFunc ;==>ProdRpts 1. The $j variable is not used and was removed. 2. Search() already contained a loop with no exit, and so should never be called a second time, so those calls were removed from the other functions. 3. The Search() function was the unconditional body of the script anyway, so the function call wrapper was removed for simplification. 4. IniRead() returns strings, so the compare is made to "1" vice 1. See if that moves the ball forward. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
LurchMan Posted January 16, 2009 Author Share Posted January 16, 2009 (edited) Thanks for the reply PsaltyDS - I was looking into it, and I found out everything was working correctly - It just wasn't running the next script. Something about the array not passing the variable so I just put the variable hard coded into the func. And I also changed it to one func as a Select...Case. If theres a certain way to pass array vars to a func that im doing wrong - Please enlighten me Edit: I figured out a really easy way of doing it now! Thanks for the help salty Opt("TrayIconDebug" , 1) $01DlyRpt1 = @ScriptDir & "\01 Dly Prd Rpt1 - After Region v1.3.exe" $06ProdRpt = @ScriptDir & "\06 Prod Rpts - After Region v1.3.exe" $RLOGCLean = @ScriptDir & "\01 RLOG Cleanup - After Region v1.3.exe" $ProcDlyRpt1 = "01 Dly Prd Rpt1 - After Region v1.3.exe" $Proc06Prod = "06 Prod Rpts - After Region v1.3.exe" Global $sFile = @Scriptdir & "\Bin\Script Config.ini" Global $aFinished[2][3] = [["01 Dly Prd Rpt1", $06ProdRpt , $Proc06Prod], _ ["06 Prod Rpts", $01DlyRpt1 , $ProcDlyRpt1]] Global $n ;~ Search for scripts to be finsihed 1 = Finished; 0 = Not finished While 1 For $n = 0 to UBound($aFinished, 1) - 1 $Read = IniRead ($sFile , $aFinished[$n][0] , "Finished" , 0) If $Read = 1 Then Start () Sleep (2000) Next Wend ;~ Run the next script Func Start () $Proc = ProcessExists($aFinished[$n][2]) If $Proc > 0 Then Else Run ($aFinished[$n][1]) EndIf EndFunc Edited January 16, 2009 by LurchMan Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end. Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 16, 2009 Share Posted January 16, 2009 (edited) Thanks for the reply PsaltyDS - I was looking into it, and I found out everything was working correctly - It just wasn't running the next script. Something about the array not passing the variable so I just put the variable hard coded into the func. And I also changed it to one func as a Select...Case. If theres a certain way to pass array vars to a func that im doing wrong - Please enlighten me Edit: I figured out a really easy way of doing it now! Thanks for the help salty Opt("TrayIconDebug" , 1) $01DlyRpt1 = @ScriptDir & "\01 Dly Prd Rpt1 - After Region v1.3.exe" $06ProdRpt = @ScriptDir & "\06 Prod Rpts - After Region v1.3.exe" $RLOGCLean = @ScriptDir & "\01 RLOG Cleanup - After Region v1.3.exe" $ProcDlyRpt1 = "01 Dly Prd Rpt1 - After Region v1.3.exe" $Proc06Prod = "06 Prod Rpts - After Region v1.3.exe" Global $sFile = @Scriptdir & "\Bin\Script Config.ini" Global $aFinished[2][3] = [["01 Dly Prd Rpt1", $06ProdRpt , $Proc06Prod], _ ["06 Prod Rpts", $01DlyRpt1 , $ProcDlyRpt1]] Global $n ;~ Search for scripts to be finsihed 1 = Finished; 0 = Not finished While 1 For $n = 0 to UBound($aFinished, 1) - 1 $Read = IniRead ($sFile , $aFinished[$n][0] , "Finished" , 0) If $Read = 1 Then Start () Sleep (2000) Next Wend ;~ Run the next script Func Start () $Proc = ProcessExists($aFinished[$n][2]) If $Proc > 0 Then Else Run ($aFinished[$n][1]) EndIf EndFunc You are still declaring your For/Next iteration variable Global ($n), which I don't like. I think that is setting you up for problems in the future. This version keeps everything in ini files, so you don't have to hard-code the configuration in the script. One ini file contains the configuration for the script, the other one is what you already had to detect "Finished": expandcollapse popup#include <Array.au3>; only for debug _ArrayDisplay() Opt("TrayIconDebug", 1) ; Config_me.ini format: ; [ShortName] (i.e. "DlyRpt1") ; ProcessName = Process Name (i.e. 01 Dly Prd Rpt1) ; ProcessExe = ExecutableToRun.exe (i.e. "01 Dly Prd Rpt1 - After Region v1.3.exe") Global $sIniConfig = @ScriptDir & "\Config_me.ini" ; Get list of sections Global $avSect = IniReadSectionNames($sIniConfig) If @error Then MsgBox(16, "Error", "Failed to read configuration file: " & $sIniConfig) Exit EndIf ; Create and populate array $avFinished ; [0][0] = count ; [n][0] = Process Name (i.e. "01 Dly Prd Rpt1") ; [n][1] = Short name (i.e. "DlyRpt1" section name from Config_me.ini) ; [n][2] = Executable To Run.exe (i.e. "01 Dly Prd Rpt1 - After Region v1.3.exe") ; [n][3] = PID of run process Global $avFinished[$avSect[0] + 1][4] = [[$avSect[0], "", ""]]; [0][0] = count For $n = 1 To $avSect[0] $avFinished[$n][0] = IniRead($sIniConfig, $avSect[$n], "ProcessName", "") $avFinished[$n][1] = $avSect[$n] $avFinished[$n][2] = IniRead($sIniConfig, $avSect[$n], "ProcessExe", "") If ($avFinished[$n][0] = "") Or ($avFinished[$n][0] = "") Then MsgBox(16, "Error", "Invalid data in config file at section: " & $avSect[$n]) Exit EndIf $avFinished[$n][2] = @ScriptDir & "\" & $avFinished[$n][2] $avFinished[$n][3] = 0; Will be PID when run Next _ArrayDisplay($avFinished, "Debug: $avFinished") ; Check for finished actions and run associated programs: Global $sFile = @ScriptDir & "\Bin\Script Config.ini" While 1 For $n = 1 To $avFinished[0][0] $sRead = IniRead($sFile, $avFinished[$n][0], "Finished", 0) If @error Then MsgBox(16, "Error", "Failure checking 'Finished' status for: " & $avFinished[$n][0]) ContinueLoop EndIf If $sRead = "1" Then $avFinished[$n][3] = Run($avFinished[$n][2], @TempDir, @SW_MINIMIZE) If @error Then MsgBox(16, "Error", "Failure running program: " & $avFinished[$n][2]) ContinueLoop EndIf Sleep(1000) Next Sleep(1000) WEnd Edit: Crossed up some of the array values. Edited January 16, 2009 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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