Sign in to follow this  
Followers 0
TecGuy

Have a loop count to 10 or exit on a return value

4 posts in this topic

I want to run the following script until either the count reaches 10 or "Program.exe" Returns a value of 0

I just cant seem to get the script to work.

For $i = 1 to 10
If $command1 = 0 Then 

        Local $x = 0
        While 1
        $command1 = RunWait(@ComSpec & " /c " & "Program.exe","",@SW_HIDE,3) 
        MsgBox(0, "Return value is", $command1)

        $x += 1
            If Not FileExists("c:\test.txt") Then
                $file = FileOpen("c:\test.txt",  2)
                FileWriteLine($file,  @MON & "/" & @MDAY & "/" & @YEAR & "  " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF) 
                FileWriteLine($file,  @CRLF) 
                FileClose($file)
                ExitLoop
            EndIf
        WEnd
    $command = Run(@ComSpec & " /c " & "Program.exe","",@SW_HIDE,3)  ;<-- 3 = handle to input AND handle to output, really useful here :) 

EndIf

Next
Exit

Thanks

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You correctly set it to loop 10 times.

I'm just confused with $command and $command1. Are they different variables?

Here's the correction:

Local $command
Local $x
For $i = 1 to 10
    If $command1 = 0 Then    
        $x = 0
        While 1
            $command1 = RunWait(@ComSpec & " /c " & "Program.exe","",@SW_HIDE,3) 
            MsgBox(0, "Return value is", $command1)
            $x += 1
            If Not FileExists("c:\test.txt") Then
                $file = FileOpen("c:\test.txt",  2)
                FileWriteLine($file,  @MON & "/" & @MDAY & "/" & @YEAR & "  " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF) 
                FileWriteLine($file,  @CRLF) 
                FileClose($file)
                ExitLoop
            EndIf
        WEnd
        $command = Run(@ComSpec & " /c " & "Program.exe","",@SW_HIDE,3)  ;<-- 3 = handle to input AND handle to output, really useful here :)
        If $command == 0 Then
            ExitLoop
        EndIf
    EndIf
Next
Exit
Edited by omikron48

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

$command1 the executable that will give the value of 0 if it processed successfully. Basically i have it run in a test mode to make sure that the server it is connecting to is not down

$command is the same program that will run in live mode if $command1 was successfull in connecting

Edited by TecGuy

Share this post


Link to post
Share on other sites

$command1 the executable that will give the value of 0 if it processed successfully. Basically i have it run in a test mode to make sure that the server it is connecting to is not down

$command is the same program that will run in live mode if $command1 was successfull in connecting

Try declaring $command1.

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  
Followers 0