Jump to content

Do Until all Arrays have been process


 Share

Recommended Posts

Hi Guys,

Could someone shed some light on working with Arrays,

For $i=0 To 30
;DO Until Loop?
$run123 = RunAs(@ComSpec & " /c " & $TestArray[$i], @systemdir, @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD)

Do i need a Do Until here?;this is where i need help is there anyway to have it end the loop when the last $TestArray[30] has been processed by $run123
Next
MsgBox(0, "", "finished") ;Denotes that function has been completed all 30 arrays have been processed
Run(Command)

I have tried adding many variation but while it is processing the arrays it pops up the msgbox and runs the specific command.

Link to comment
Share on other sites

You don't show how thw array is structured so the best we can do is deal in geheralities. Usually with an array you will be looking into using a For/Next loop instead of Do/Until.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Global $TestArray[31]

For $i=0 To 30 Step 1
  $run123 = RunAs(@ComSpec & " /c " & $TestArray[$i], @systemdir, @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD)
Next

MsgBox(0, "", "finished") ;Denotes that function has been completed all 30 arrays have been processed

This code should do exactly what you want. Else you need to describe again.

Hi Guys,

Could someone shed some light on working with Arrays,

For $i=0 To 30
;DO Until Loop?
$run123 = RunAs(@ComSpec & " /c " & $TestArray[$i], @systemdir, @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD)

Do i need a Do Until here?;this is where i need help is there anyway to have it end the loop when the last $TestArray[30] has been processed by $run123
Next
MsgBox(0, "", "finished") ;Denotes that function has been completed all 30 arrays have been processed
Run(Command)

I have tried adding many variation but while it is processing the arrays it pops up the msgbox and runs the specific command.

Edited by Xibalba
Link to comment
Share on other sites

Sorry I didnt explain in more detail:

If I was to use Do/Until were exactly would i place that within the function, further more how can you capture that the last Array has been processed, then perform what ever command.

thanks again.

#include <Constants.au3>
#include <process.au3>
#include <WindowsConstants.au3>
Global $file = "", $test = ""

_test123()
Func _test123()
    Local $TestArray[31]

    $TestArray[0] = $file & " " & ' ' & " " & $test
    $TestArray[1] = $file & " " & ' ' & " " & $test
    $TestArray[2] = $file & " " & ' ' & " " & $test
    $TestArray[3] = $file & " " & ' ' & " " & $test
    $TestArray[4] = $file & " " & ' ' & " " & $test
    $TestArray[5] = $file & " " & ' ' & " " & $test
    $TestArray[6] = $file & " " & ' ' & " " & $test
    $TestArray[7] = $file & " " & ' ' & " " & $test
    $TestArray[8] = $file & " " & ' ' & " " & $test
    $TestArray[9] = $file & " " & ' ' & " " & $test
    $TestArray[10] = $file & " " & ' ' & " " & $test
    $TestArray[11] = $file & " " & ' ' & " " & $test
    $TestArray[12] = $file & " " & ' ' & " " & $test
    $TestArray[13] = $file & " " & ' ' & " " & $test
    $TestArray[14] = $file & " " & ' ' & " " & $test
    $TestArray[15] = $file & " " & ' ' & " " & $test
    $TestArray[16] = $file & " " & ' ' & " " & $test
    $TestArray[17] = $file & " " & ' ' & " " & $test
    $TestArray[18] = $file & " " & ' ' & " " & $test
    $TestArray[19] = $file & " " & ' ' & " " & $test
    $TestArray[20] = $file & " " & ' ' & " " & $test
    $TestArray[21] = $file & " " & ' ' & " " & $test
    $TestArray[22] = $file & " " & ' ' & " " & $test
    $TestArray[23] = $file & " " & ' ' & " " & $test
    $TestArray[24] = $file & " " & ' ' & " " & $test
    $TestArray[25] = $file & " " & ' ' & " " & $test
    $TestArray[26] = $file & " " & ' ' & " " & $test
    $TestArray[27] = $file & " " & ' ' & " " & $test
    $TestArray[28] = $file & " " & ' ' & " " & $test
    $TestArray[29] = $file & " " & ' ' & " " & $test
    $TestArray[30] = $file & " " & ' ' & " " & $test
    For $i = 0 To 31
        $pid = Run(@ComSpec & " /c " & $TestArray[$i], "", @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)
    Next
    MsgBox(0, "", "finished") ;Denotes that function has been completed all 30 arrays have been processed
    Run("Command")
EndFunc   ;==>_test123
Edited by Monolith
Link to comment
Share on other sites

Try this for a start. You are still trying to read an array post that doesn't exist (index 31).

#include <Constants.au3>
#include <process.au3>
#include <WindowsConstants.au3>
Global $file = "", $test = ""

_test123()
MsgBox(0, "", "If you see this text the function test123 has been run without errors.")

Func _test123()
    Local $TestArray[31]

    $TestArray[0] = $file & " " & ' ' & " " & $test
    $TestArray[1] = $file & " " & ' ' & " " & $test
    $TestArray[2] = $file & " " & ' ' & " " & $test
    $TestArray[3] = $file & " " & ' ' & " " & $test
    $TestArray[4] = $file & " " & ' ' & " " & $test
    $TestArray[5] = $file & " " & ' ' & " " & $test
    $TestArray[6] = $file & " " & ' ' & " " & $test
    $TestArray[7] = $file & " " & ' ' & " " & $test
    $TestArray[8] = $file & " " & ' ' & " " & $test
    $TestArray[9] = $file & " " & ' ' & " " & $test
    $TestArray[10] = $file & " " & ' ' & " " & $test
    $TestArray[11] = $file & " " & ' ' & " " & $test
    $TestArray[12] = $file & " " & ' ' & " " & $test
    $TestArray[13] = $file & " " & ' ' & " " & $test
    $TestArray[14] = $file & " " & ' ' & " " & $test
    $TestArray[15] = $file & " " & ' ' & " " & $test
    $TestArray[16] = $file & " " & ' ' & " " & $test
    $TestArray[17] = $file & " " & ' ' & " " & $test
    $TestArray[18] = $file & " " & ' ' & " " & $test
    $TestArray[19] = $file & " " & ' ' & " " & $test
    $TestArray[20] = $file & " " & ' ' & " " & $test
    $TestArray[21] = $file & " " & ' ' & " " & $test
    $TestArray[22] = $file & " " & ' ' & " " & $test
    $TestArray[23] = $file & " " & ' ' & " " & $test
    $TestArray[24] = $file & " " & ' ' & " " & $test
    $TestArray[25] = $file & " " & ' ' & " " & $test
    $TestArray[26] = $file & " " & ' ' & " " & $test
    $TestArray[27] = $file & " " & ' ' & " " & $test
    $TestArray[28] = $file & " " & ' ' & " " & $test
    $TestArray[29] = $file & " " & ' ' & " " & $test
    $TestArray[30] = $file & " " & ' ' & " " & $test
    For $i = 0 To 30
        $pid = Run(@ComSpec & " /c " & $TestArray[$i], "", @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)
    Next
    Run("Command")
EndFunc   ;==>_test123

Sorry I didnt explain in more detail:

If I was to use Do/Until were exactly would i place that within the function, further more how can you capture that the last Array has been processed, then perform what ever command.

thanks again.

#include <Constants.au3>
#include <process.au3>
#include <WindowsConstants.au3>
Global $file = "", $test = ""

_test123()
Func _test123()
    Local $TestArray[31]

    $TestArray[0] = $file & " " & ' ' & " " & $test
    $TestArray[1] = $file & " " & ' ' & " " & $test
    $TestArray[2] = $file & " " & ' ' & " " & $test
    $TestArray[3] = $file & " " & ' ' & " " & $test
    $TestArray[4] = $file & " " & ' ' & " " & $test
    $TestArray[5] = $file & " " & ' ' & " " & $test
    $TestArray[6] = $file & " " & ' ' & " " & $test
    $TestArray[7] = $file & " " & ' ' & " " & $test
    $TestArray[8] = $file & " " & ' ' & " " & $test
    $TestArray[9] = $file & " " & ' ' & " " & $test
    $TestArray[10] = $file & " " & ' ' & " " & $test
    $TestArray[11] = $file & " " & ' ' & " " & $test
    $TestArray[12] = $file & " " & ' ' & " " & $test
    $TestArray[13] = $file & " " & ' ' & " " & $test
    $TestArray[14] = $file & " " & ' ' & " " & $test
    $TestArray[15] = $file & " " & ' ' & " " & $test
    $TestArray[16] = $file & " " & ' ' & " " & $test
    $TestArray[17] = $file & " " & ' ' & " " & $test
    $TestArray[18] = $file & " " & ' ' & " " & $test
    $TestArray[19] = $file & " " & ' ' & " " & $test
    $TestArray[20] = $file & " " & ' ' & " " & $test
    $TestArray[21] = $file & " " & ' ' & " " & $test
    $TestArray[22] = $file & " " & ' ' & " " & $test
    $TestArray[23] = $file & " " & ' ' & " " & $test
    $TestArray[24] = $file & " " & ' ' & " " & $test
    $TestArray[25] = $file & " " & ' ' & " " & $test
    $TestArray[26] = $file & " " & ' ' & " " & $test
    $TestArray[27] = $file & " " & ' ' & " " & $test
    $TestArray[28] = $file & " " & ' ' & " " & $test
    $TestArray[29] = $file & " " & ' ' & " " & $test
    $TestArray[30] = $file & " " & ' ' & " " & $test
    For $i = 0 To 31
        $pid = Run(@ComSpec & " /c " & $TestArray[$i], "", @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)
    Next
    MsgBox(0, "", "finished") ;Denotes that function has been completed all 30 arrays have been processed
    Run("Command")
EndFunc   ;==>_test123

Link to comment
Share on other sites

Hi Xibalba,

Unfortunately this did not work as desired.

It executes all 30 of the arrays in seperate cmd.exe's and my machine almost halted, then it half way throught before all 33 arrays had been processed in cmd.exe it pops up the msgbox.

Global $TestArray[31]

For $i=0 To 30 Step 1
  $run123 = RunAs(@ComSpec & " /c " & $TestArray[$i], @systemdir, @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD)
Next

MsgBox(0, "", "finished") ;Denotes that function has been completed all 30 arrays have been processed

This code should do exactly what you want. Else you need to describe again.

Link to comment
Share on other sites

33 arrays?

Anyway, try adding a sleep after each call:

Global $TestArray[31]

For $i=0 To 30 Step 1
  $run123 = RunAs(@ComSpec & " /c " & $TestArray[$i], @systemdir, @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD)
  Sleep(5000) ; Will wait 5 seconds
Next

MsgBox(0, "", "finished") ;Denotes that function has been completed all 30 arrays have been processed

Also, check out the WinWaitClose() function in AutoIt help.

Hi Xibalba,

Unfortunately this did not work as desired.

It executes all 30 of the arrays in seperate cmd.exe's and my machine almost halted, then it half way throught before all 33 arrays had been processed in cmd.exe it pops up the msgbox.

Link to comment
Share on other sites

Try this for a start. You are still trying to read an array post that doesn't exist (index 31).

Hi Again Xibalba,

sorry that was a typo my bad.

when monitoring the execution of test123() func i see that it launches in batches of 5-10 instances of cmd.exe and child process for each of those cmd.exe which in this case $file = status.exe.

Sorry as I am still learning working with Arrays, but I am needing each array to be processed and closed before the next one, this is to reduce ram and CPU utilization.

Edited by Monolith
Link to comment
Share on other sites

33 arrays?

Anyway, try adding a sleep after each call:

Global $TestArray[31]

For $i=0 To 30 Step 1
  $run123 = RunAs(@ComSpec & " /c " & $TestArray[$i], @systemdir, @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD)
  Sleep(5000) ; Will wait 5 seconds
Next

MsgBox(0, "", "finished") ;Denotes that function has been completed all 30 arrays have been processed

Also, check out the WinWaitClose() function in AutoIt help.

Will check on the winwaitclose() and report back, thanks again

Link to comment
Share on other sites

@Xibalba

Questions:

Why are you using RunAs() when you are not running it with any credentials and your parameters are incorrect anyway?

Why would he want to use $STDERR_CHILD + $STDOUT_CHILD when he's not reading the StdStream?

Why would you suggest a 5 second sleep when RunWait() will stop it from proceeding until the current call is finished?

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

@Xibalba

Questions:

Why are you using RunAs() when you are not running it with any credentials and your parameters are incorrect anyway?

- Sorry Im modifying what i paste in Forums

$pid = RunAs($adminuser, "", $adminpwd, 0, @ComSpec & " /c " & $TestArray[$i], @systemdir, @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD)

Why would he want to use $STDERR_CHILD + $STDOUT_CHILD when he's not reading the StdStream?

- I was messing around with trying output child process to a Control.

Why would you suggest a 5 second sleep when RunWait() will stop it from proceeding until the current call is finished?

Link to comment
Share on other sites

@GEOSoft:

I suppose you mean @Monolith. If not:

Why are you using RunAs() when you are not running it with any credentials and your parameters are incorrect anyway?

I'm not. Monolith is.

Why would he want to use $STDERR_CHILD + $STDOUT_CHILD when he's not reading the StdStream?

No idea, ask him.

Why would you suggest a 5 second sleep when RunWait() will stop it from proceeding until the current call is finished?

Because it is a fast (and ugly) workaround. Sleep() and WinWaitClose() was suggested to point Monolith in the right direction. RunWait() is probably the optimal solution for what Monolith tries to accomplish.

As the topic suggests, the main problem for OP was understanding arrays, which I tried to explain (and solve).

@Xibalba

Questions:

Why are you using RunAs() when you are not running it with any credentials and your parameters are incorrect anyway?

Why would he want to use $STDERR_CHILD + $STDOUT_CHILD when he's not reading the StdStream?

Why would you suggest a 5 second sleep when RunWait() will stop it from proceeding until the current call is finished?

Link to comment
Share on other sites

Hi again,

RunAsWait() i cant belive I over looked that :) thanks, but I found RunAsWait bit slow, so what i implemented was adding to command line && Exit

which will exit when command completed successfully so only waiting .5-1.5 secs.

$pid = RunAs($adminuser, "", $adminpwd, 0, @ComSpec & " /c " & $TestArray[$i] & " " & "&&" & " " & "Exit", @systemdir, @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD)

with debuggin scripts, #AutoIt3Wrapper_run_debug_mode=Y works greate but is there anyway to get a time for when each

$pid = RunAs($adminuser, "", $adminpwd, 0, @ComSpec & " /c " & $TestArray[$i], @systemdir, @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD)

is processed?

just so i can bench mark?

thanks everyone thus far for your help.

Edited by Monolith
Link to comment
Share on other sites

Glad you solved it.

As for benchmarking, checkout the TimerInit and TimerDiff functions, example:

$begin = TimerInit()
sleep(3000)
$dif = TimerDiff($begin)
MsgBox(0,"Time Difference",$dif)

Hi again,

RunAsWait() i cant belive I over looked that :) thanks, but I found RunAsWait bit slow, so what i implemented was adding to command line && Exit

which will exit when command completed successfully so only waiting .5-1.5 secs.

$pid = RunAs($adminuser, "", $adminpwd, 0, @ComSpec & " /c " & $TestArray[$i] & " " & "&&" & " " & "Exit", @systemdir, @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD)

with debuggin scripts, #AutoIt3Wrapper_run_debug_mode=Y works greate but is there anyway to get a time for when each

$pid = RunAs($adminuser, "", $adminpwd, 0, @ComSpec & " /c " & $TestArray[$i], @systemdir, @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD)

is processed?

just so i can bench mark?

thanks everyone thus far for your help.

Link to comment
Share on other sites

Glad you solved it.

As for benchmarking, checkout the TimerInit and TimerDiff functions, example:

$begin = TimerInit()
sleep(3000)
$dif = TimerDiff($begin)
MsgBox(0,"Time Difference",$dif)

Hi Again,

Not exactly what i was looking for,

I am wanting output to console with a time stamp for the entire script.

anyway thnx

Link to comment
Share on other sites

@GEOSoft:

I suppose you mean @Monolith.

My BAD!!

Of course you are correct. I'm sorry about that.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...