Hi,
There's a procedure that goes through a list and opens a channel for each
of its elements.
I'd need a vwait for each of the channels, like
vwait exec_0
vwait exec_1
...
0, 1, ... are the execution ids (exec_id).
How can I do this?
LuÃs Mendes
Hi,
There's a procedure that goes through a list and opens a channel for each
of its elements.
I'd need a vwait for each of the channels, like
vwait exec_0
vwait exec_1
...
0, 1, ... are the execution ids (exec_id).
How can I do this?
On Mon, 3 Jun 2024 18:01:14 -0000 (UTC), Rich wrote:
Luis Mendes <luisXXXlupeXXX@gmail.com> wrote:The expression was perhaps too simplistic.
Hi,
There's a procedure that goes through a list and opens a channel for
each of its elements.
I'd need a vwait for each of the channels, like vwait exec_0 vwait
exec_1 ...
0, 1, ... are the execution ids (exec_id).
How can I do this?
You can't vwait on channels. vwait waits on a variable to be changed.
What are you /really/ trying to do?
As said in the first message, I want to use several channels at the same
time to perform some 'exec' commands and want to wait for the complete execution of all of them.
On Mon, 3 Jun 2024 18:01:14 -0000 (UTC), Rich wrote:
Luis Mendes <luisXXXlupeXXX@gmail.com> wrote:
Hi,
There's a procedure that goes through a list and opens a channel for
each of its elements.
I'd need a vwait for each of the channels, like vwait exec_0 vwait
exec_1 ...
0, 1, ... are the execution ids (exec_id).
How can I do this?
You can't vwait on channels. vwait waits on a variable to be changed.
What are you /really/ trying to do?The expression was perhaps too simplistic.
As said in the first message, I want to use several channels at the same
time to perform some 'exec' commands and want to wait for the complete execution of all of them.
On Tue, 04 Jun 2024 12:33:10 +0000, Robert Heller wrote:
At 04 Jun 2024 11:34:37 GMT Luis Mendes <luisXXXlupeXXX@gmail.com>I have everything working fine, from opening a channel, to setting up the readable event, to closing it and setting the variable that vwait is
wrote:
On Mon, 3 Jun 2024 18:01:14 -0000 (UTC), Rich wrote:
Luis Mendes <luisXXXlupeXXX@gmail.com> wrote:The expression was perhaps too simplistic.
Hi,
There's a procedure that goes through a list and opens a channel for >>>>> each of its elements.
I'd need a vwait for each of the channels, like vwait exec_0 vwait
exec_1 ...
0, 1, ... are the execution ids (exec_id).
How can I do this?
You can't vwait on channels. vwait waits on a variable to be
changed.
What are you /really/ trying to do?
As said in the first message, I want to use several channels at the
same time to perform some 'exec' commands and want to wait for the
complete execution of all of them.
You description here is very unclear. 'exec' does not create channels
and you can't "vwait" on a channel anyway.
Maybe what you want is:
# launch a subprocess, capturing its output with a "pipe", which will be
read # by a specified script. The script will have the pipe channel
appended to # it.
proc pipeCommand {commandString commpletionScript} {
if {[catch {open "|$commandString" r} pipe]} {
puts stderr "Error starting $commandString: $pipe"
return
}
fileevent $pipe readable "$commpletionScript $pipe"
}
# read a pipe as data becomes available. Close the pipe when the process
# completes.
proc typicalCompletionProc {pipe} {
if {[gets $pipe line] >= 0} {
puts $line;# one line of output from the process. Maybe parse it?
} else {
# EOF or ERROR on pipe: process completed, possibly with an error
if {[catch {close $pipe} finalResult]} {
# process completed with an error puts stderr "process
completed with an error: $finalResult"
} else {
# process completed with success puts "process completed:
$finalResult"
}
}
}
# fire up some commands in the background, and wait for them to complete
pipeCommand "uname -a" typicalCompletionProc pipeCommand "ls"
typicalCompletionProc pipeCommand "find $HOME/" typicalCompletionProc
pipeCommand "make" typicalCompletionProc
# enter event loop to allow fileevents to process (read the pipes #
asyncroniously) The variable Forever will never be changed, so this #
statement never returns. Note: if this was done in wish or with #
'package require Tk', this last line would not be needed at all.
vwait Forever
waiting for, in your example 'Forever'.
What I'd like to know is how to wait for several Forever_$exec_id
variables of channels that are open at the same time.
I just need this last part.
On Tue, 04 Jun 2024 12:33:10 +0000, Robert Heller wrote:
At 04 Jun 2024 11:34:37 GMT Luis Mendes <luisXXXlupeXXX@gmail.com>
wrote:
On Mon, 3 Jun 2024 18:01:14 -0000 (UTC), Rich wrote:
Luis Mendes <luisXXXlupeXXX@gmail.com> wrote:The expression was perhaps too simplistic.
Hi,
There's a procedure that goes through a list and opens a channel for
each of its elements.
I'd need a vwait for each of the channels, like vwait exec_0 vwait
exec_1 ...
0, 1, ... are the execution ids (exec_id).
How can I do this?
You can't vwait on channels. vwait waits on a variable to be
changed.
What are you /really/ trying to do?
As said in the first message, I want to use several channels at the
same time to perform some 'exec' commands and want to wait for the
complete execution of all of them.
You description here is very unclear. 'exec' does not create channels
and you can't "vwait" on a channel anyway.
Maybe what you want is:
# launch a subprocess, capturing its output with a "pipe", which will be read # by a specified script. The script will have the pipe channel appended to # it.
proc pipeCommand {commandString commpletionScript} {
if {[catch {open "|$commandString" r} pipe]} {
puts stderr "Error starting $commandString: $pipe"
return
}
fileevent $pipe readable "$commpletionScript $pipe"
}
# read a pipe as data becomes available. Close the pipe when the process
# completes.
proc typicalCompletionProc {pipe} {
if {[gets $pipe line] >= 0} {
puts $line;# one line of output from the process. Maybe parse it?
} else {
# EOF or ERROR on pipe: process completed, possibly with an error
if {[catch {close $pipe} finalResult]} {
# process completed with an error puts stderr "process
completed with an error: $finalResult"
} else {
# process completed with success puts "process completed:
$finalResult"
}
}
}
# fire up some commands in the background, and wait for them to complete pipeCommand "uname -a" typicalCompletionProc pipeCommand "ls" typicalCompletionProc pipeCommand "find $HOME/" typicalCompletionProc pipeCommand "make" typicalCompletionProc
# enter event loop to allow fileevents to process (read the pipes # asyncroniously) The variable Forever will never be changed, so this # statement never returns. Note: if this was done in wish or with #I have everything working fine, from opening a channel, to setting up the readable event, to closing it and setting the variable that vwait is
'package require Tk', this last line would not be needed at all.
vwait Forever
waiting for, in your example 'Forever'.
What I'd like to know is how to wait for several Forever_$exec_id
variables of channels that are open at the same time.
I just need this last part.
I have everything working fine, from opening a channel, to setting up the readable event, to closing it and setting the variable that vwait is
waiting for, in your example 'Forever'.
What I'd like to know is how to wait for several Forever_$exec_id
variables of channels that are open at the same time.
I just need this last part.
On 6/3/24 17:26, Luis Mendes wrote:
...
I'd need a vwait for each of the channels, like
vwait exec_0
vwait exec_1
...
0, 1, ... are the execution ids (exec_id).
How can I do this?
Might be a pattern for which TIP#455 could be of use, see
https://core.tcl-lang.org/tips/doc/trunk/tip/455.md
Cheers,
Christian
...
I'd need a vwait for each of the channels, like
vwait exec_0
vwait exec_1
...
0, 1, ... are the execution ids (exec_id).
How can I do this?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 498 |
Nodes: | 16 (2 / 14) |
Uptime: | 53:09:27 |
Calls: | 9,810 |
Calls today: | 12 |
Files: | 13,754 |
Messages: | 6,190,510 |