madasraka Posted July 5, 2010 Share Posted July 5, 2010 (edited) I have a problem. Windows 7 64bit Code as simple as: Run("notepad.exe") $pid = WinGetProcess("[CLASS:Notepad]") MsgBox(4096, "PID is", $pid) $PID is executed to fast so that MsgBox gives -1 unless i keep opened notepad opened and run script again. I also noticed that i'd have to add delay in some of my scripts or some sort of barriers so that msgbox would work right or work at all. Some of my scripts (very rare but its there) skip msgbox for unknown reasons. I know if i put 1 extra msgbox in front of one that is skipped over, both will work, but if i remove one then none will work. I dont think my computer is so fast that it pass lines of code as if "OOPS didn't see that one" IN the example above it feels like Notepad is launched but not started yet. $pid is then executed and because notepad is still not executed there is no PID return. Its strange why this works like that but if i place a delay of 0.1 second betwin 1st and 2nd line, it will work fine. What is wrong, is it windows or autoit ? I'd like to think autoit executes the application but not waiting for CPU to confirm execution is passed so that next line executed before CPU says that previous line is understood and executed. (just a thought, i have no idea how it works) Any ideas ? Edited July 5, 2010 by madasraka Link to comment Share on other sites More sharing options...
omikron48 Posted July 5, 2010 Share Posted July 5, 2010 (edited) Try using WinWait or ProcessWait, after the Run command to make your script wait until Notepad is running before proceeding with the next line. Edited July 5, 2010 by omikron48 Link to comment Share on other sites More sharing options...
madasraka Posted July 5, 2010 Author Share Posted July 5, 2010 i cant, this example involved executing external application, but my other scripts are not like that, they are simply functions in which sometimes msgbox just wont pup up at the end of function of within one of "If" statements. For Example: $Var = "0" While 1 Assign ("Var" $Var+1) If $Var = 10 Then msgbox (0,'','its ten') Endif Wend This is the simplest example i can make but in reality its much more complex then this and there are plenty of conditions "If's" which would trigger one or another msgbox. Sometimes msgbox just wont show up at all unless delay is added. Its like each process needs to have "processwait" I get that it wuld make sense for check of process exist before executing next line of code, but ist "SCRIPTED" means one step at the time ? I thought that Run start specified process and then executes next line as appose to RunWait pause script till process closed Link to comment Share on other sites More sharing options...
sahsanu Posted July 5, 2010 Share Posted July 5, 2010 they are simply functions in which sometimes msgbox just wont pup up at the end of function of within one of "If" statements. Hello, I've no problem with below example scripts: $pid=Run("notepad.exe") If @error Then MsgBox(16,"Error","Error launching app") Else MsgBox(4096, "PID is", $pid) EndIf $Var = "0" While 1 $Var += 1 ;Assign ("Var", $Var+1) If $Var = 10 Then Msgbox (0,'','its ten') Exitloop Endif Wend Regards, sahsanu Link to comment Share on other sites More sharing options...
madasraka Posted July 5, 2010 Author Share Posted July 5, 2010 I've no problem with below example scripts: $pid=Run("notepad.exe") If @error Then MsgBox(16,"Error","Error launching app") Else MsgBox(4096, "PID is", $pid) EndIf $Var = "0" While 1 $Var += 1 ;Assign ("Var", $Var+1) If $Var = 10 Then Msgbox (0,'','its ten') Exitloop Endif Wend Sure and i dont too. Try this one. Run("notepad.exe") $pid = WinGetProcess("[CLASS:Notepad]") MsgBox(4096, "PID is", $pid) MsgBox will pop before notepad opened and result will be -1 because $pid = WinGetProcess("[CLASS:Notepad]") was to slow to acquire PID ? or msgox was to fast ? Thats the problem am having. Link to comment Share on other sites More sharing options...
omikron48 Posted July 5, 2010 Share Posted July 5, 2010 Like I said, stick in a wait of sorts to make sure that whatever external program you want to run is already running before your script proceeds with execution. That's what you need to do for that situation. If it's a different scenario, I can't comment without any specifics. Link to comment Share on other sites More sharing options...
JohnOne Posted July 6, 2010 Share Posted July 6, 2010 Your code just dosent make good sense, infact its bad practice, just change it. Even this will do, if you are determined not to check for errors of wait for window. $pid = Run("notepad.exe") MsgBox(4096, "PID is", $pid) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
madasraka Posted July 6, 2010 Author Share Posted July 6, 2010 code is from help file and it does make sense. 1st launch application 2nd get application PID using wingetprocess 3rd output result it doesnt get simpler then that yet its not working right. Am just saying. Link to comment Share on other sites More sharing options...
JohnOne Posted July 6, 2010 Share Posted July 6, 2010 I see, its an example from the helpfile. Nevertheless, its a bad example, and if I were you I would not follow it. I think I seen a thread somewhere to report dodgyness in the helpfile. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. 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