Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simultaneous exec commands 1

Status
Not open for further replies.

mlowe9

Programmer
Apr 3, 2002
221
US
I want to run multiple exec commands simultaneously. I understand there isn't a way to REALLY run them simultaneously, but I want them to run together.

For example, I have to run this script 10 times. Rather than do it one at a time, each waiting for the previous one to finish, I would like to run them together, allowing them to finish at (about) the same time. I'm thinking this will speed up the process.

Here's what I'm doing now:

foreach site $siteList {
eval [exec -keepnewline script_name $site]
}

Can anyone tell me how to do this? Will it even help with the speed issue? Any other suggestions?
 
Here's what I came up with on my own:

####################################
# Get Queues for each site
foreach site $site_list {
eval [exec -keepnewline $setenv -site tcl $site]
set pid($site) [open "| ./CallMSIAttach.tcl" r]
}
# This waits until the CallMSIAttach scripts are finished
foreach site $site_list {
while {[gets $pid($site) results] != -1} {
set output($site) results
}
}

See any problems with it? The first foreach group starts the script for each "site", the second foreach group runs until the scripts are finished.
 
you can use the open command to run programs simultaneously. the open command also lets you recieve output from the program and input to the program

Breadcrust (aka J@red)

Web - E-mail - net-head@softhome.net
Linux Reg. Number - 307180
 
So you're saying what I have is good?
 
Thank you. Is there a better way to wait for them to finish, besides having a separate loop?
 
Depending on how your application works, you could do event-driven programming, using fileevent to register asynchronous read handlers for the channels. I'd suggest going to the Tcl'ers Wiki ( for more information, perhaps starting with the page "fileevent,"
- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Thanks to everyone for their help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top