if { ${action1_checked} } {
exec prog1 &
}
if { ${action2_checked} } {
exec prog2 &
}
if { ${action3_checked} } {
exec prog3 &
}
So the thing is that all selected actions are launched simultaneously and they each end anytime, conclusion is that I'm loosing the fact that action3 must be launched after action2 ends which must be launched after action1 ends.
Hello,
I'm pretty new to TCL/TK and this time it's too much for me !
I did a Tk GUI where I can select several actions with check boxes
and then when I click on a button I want all those actions to be
executed in background but keeping the actions order.
So let's say I've checkboxes action1, action2 and action3. For now I
have somewhere in the button's proc the following lines :
if { ${action1_checked} } {
exec prog1 &
}
if { ${action2_checked} } {
exec prog2 &
}
if { ${action3_checked} } {
exec prog3 &
}
So the thing is that all selected actions are launched simultaneously
and they each end anytime, conclusion is that I'm loosing the fact
that action3 must be launched after action2 ends which must be
launched after action1 ends.
I googled a lot of things, got several answers I'm not able to
understand because too advanced for me !
So if someone could provide me specific info to this case I would be
grateful !
Hello,
I'm pretty new to TCL/TK and this time it's too much for me !
I did a Tk GUI where I can select several actions with check boxes and then when I click on a button I want all those actions to be executed in background but keeping the actions order.
So let's say I've checkboxes action1, action2 and action3.
For now I have somewhere in the button's proc the following lines :
if { ${action1_checked} } {
exec prog1 &
}
if { ${action2_checked} } {
exec prog2 &
}
if { ${action3_checked} } {
exec prog3 &
}
So the thing is that all selected actions are launched simultaneously and they each end anytime, conclusion is that I'm loosing the fact that action3 must be launched after action2 ends which must be launched after action1 ends.
I googled a lot of things, got several answers I'm not able to understand because too advanced for me !
So if someone could provide me specific info to this case I would be grateful !
Thanks.
On Sunday, December 11, 2022 at 2:50:34 PM UTC-6, my DIY wrote:
I did a Tk GUI where I can select several actions with check boxes and then when I click on a button I want all those actions to be executed in background but keeping the actions order.
On 12/12/2022 08:34, Bezoar wrote:This is a better idea.
On Sunday, December 11, 2022 at 2:50:34 PM UTC-6, my DIY wrote:Because vwaits nest, I prefer to use them sparingly. They are not needed here. You can just store the commands in a list and when one command finishes, start the next:
I did a Tk GUI where I can select several actions with check boxes and then when I click on a button I want all those actions to be executed in background but keeping the actions order.
#!/usr/bin/env tclsh
proc log {str} {
# Simplistic logging
puts $str
}
proc serialexec {args} {
variable serialexec
lappend serialexec $args
log "Queued command: $args"
if {[llength $serialexec] == 1} {
# First command can immediately be started
serialrun
}
}
proc serialrun {} {
variable serialexec
set cmd [lindex $serialexec 0]
set fd [open "|$cmd 2>@1"]
log "Started command: $cmd, pid = [pid $fd]"
fconfigure $fd -blocking 0
fileevent $fd readable [list callback $fd]
}
proc callback {fd} {
if {[eof $fd]} {
variable serialexec
# The channel must be blocking to get the exit code
fconfigure $fd -blocking 1
try {
close $fd
set retcode 0
} trap {CHILDSTATUS} {err info} {
set retcode [lindex [dict get $info -errorcode] end]
} on error {err info} {
# Something unexpected happened
log $err
exit
}
set serialexec [lassign $serialexec cmd]
log "Command finished: $cmd, exit code = $retcode"
if {[llength $serialexec]} {
# Start the next queued command
serialrun
} else {
# All commands have finished
exit
}
} else {
if {[gets $fd line] >= 0} {
# Optionally log the output of the command
log $line
}
}
}
serialexec sleep 5
serialexec sleep 3
serialexec sleep 4
vwait forever
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 716 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 55:42:46 |
| Calls: | 12,117 |
| Calls today: | 8 |
| Files: | 15,010 |
| Messages: | 6,518,650 |
| Posted today: | 2 |