Jump to content
Sign in to follow this  
madasraka

Code scipt lines ?

Recommended Posts

madasraka

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 by madasraka

Share this post


Link to post
Share on other sites
omikron48

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 by omikron48

Share this post


Link to post
Share on other sites
madasraka

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

Share this post


Link to post
Share on other sites
sahsanu

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

Share this post


Link to post
Share on other sites
madasraka

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.

Share this post


Link to post
Share on other sites
omikron48

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.

Share this post


Link to post
Share on other sites
JohnOne

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.

Share this post


Link to post
Share on other sites
madasraka

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×