# mkcmd_wait executes the command given by parameter "cmd" in procedure "startProc"
#
# is called from mkcommand.4/mkCmd_wait: 
# ... exec $xtermcall -e $wishcall $xtem_path/xtem_async $name &...
#
# as a concrete example:
#
#    set xtermcall xterm
#    set wishcall /usr/local/bin/wishx
#    set name  [tk appname]
#    set w_mkCmd [eval exec $xtermcall -e $wishcall $xtem_path/xtem_async $name &]
#    tkwait variable n_mkCmd
#
# Copyright (C) 1999  G. Lamprecht, W. Lotz, R. Weibezahn; IWD, Bremen University

proc killProc {}  {global pid; foreach p $pid {catch "kill SIGKILL $p"} }

proc startProc {cmd} {
  global  env pid xtem
  puts stdout "----- $cmd -----"; flush stdout
  set pid [eval exec $cmd &]
  send  $xtem "set p_mkCmd $pid; TestPut 4 PID=$pid"
  flush stdout
}

signal trap SIGHUP  {destroy .}
signal trap SIGTERM {destroy .}
signal trap SIGCHLD \
       {global pid;if ![catch "wait $pid"] {puts stdout "";flush stdout;send $xtem mkCmd_xit}}

signal ignore SIGINT
signal ignore SIGQUIT

set pid 0
wm withdraw .
set xtem [lindex $argv 0]
send $xtem  set n_mkCmd \"[winfo name .]\"
