''Martin S. Weber'' Ephaeton at gmx dot net Homepage still under construction :) Wiki stuff: * [Errx] * [AtExit Handlers] * Some socket examples in [Einfach Tcl] * [pathentry] * [block-select] * [sizepanel] * multiple value [set] * likes [Toasting procs] * [Simpletracer], with help from [RS] & [MS] Next to come: * finish [sizepanel] * finish [pathentry] * onInit * Remarks about gcc ---- [Category Person] ---- This is for suchenwi/ tcl chatroom: set ::bexec_runs 0 set ::bexec_result "" proc bexec what { global bexec_runs bexec_result set fname [file join $::env(HOME) tmp cmd_run_lock_$::env(USER)_[pid]] while {[catch {set fp [open $fname {WRONLY CREAT EXCL}]}]} { puts stderr "Lock busy, will retry." after 200 "set ::retry 0" vwait ::retry } puts stderr "Got the Lock for \"[string range $what 0 99]...\"." # reset results set ::bexec_result "" puts stderr "Executing $what..." set bexec_runs 1 set f [open |$what] #fconfigure $f -translation none fileevent $f readable [list bexec_read $f] vwait bexec_runs file delete -force [file join $::env(HOME) tmp cmd_run_lock_$::env(USER)_[pid]] puts stderr "Released the Lock for \"[string range $what 0 99]...\"." return $bexec_result } proc bexec_read {f} { set data [read $f] if [eof $f] { close $f set ::bexec_runs 0 } append ::bexec_result $data } # demo1: set tfile [open tst.sh w] puts $tfile {#!/bin/sh echo "output1" sleep 3 echo "output2"} close $tfile puts [bexec "sh tst.sh"] puts [bexec "sh tst.sh"] ;# <-- this one will wait. # demo2: pack [button .b -text "run" -command {puts [bexec "sh tst.sh"]}] -expand 1 -fill both Output: Got the Lock for "sh tst.sh...". Executing sh tst.sh... Released the Lock for "sh tst.sh...". output1 output2 Got the Lock for "sh tst.sh...". Executing sh tst.sh... Released the Lock for "sh tst.sh...". output1 output2 # hit the run button one time Got the Lock for "sh tst.sh...". Executing sh tst.sh... Released the Lock for "sh tst.sh...". output1 output2 # hit the run button many times # "many" = enough so that one gets fired and at least TWO are # outstanding. Got the Lock for "sh tst.sh...". Executing sh tst.sh... Released the Lock for "sh tst.sh...". output1 output2 Got the Lock for "sh tst.sh...". Executing sh tst.sh... Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. Lock busy, will retry. # ad infitum... lockfile never goes away.