When you do this sort of thing:
set fid [ open |$program ]
does closing the fid kill the process, always?
No. Closing the fid closes the pipe. Next time the process writes to the
pipe, it gets a sigpipe. If it doesn't write to the pipe, or otherwise
catches or avoids the sigpipe, then it can keep running.
--
Darren New
San Diego, CA, USA (PST). Cryptokeys on demand.
"This wine goes good with feet."
In THAT case, how do I get the pid of the process opened by
"set fid [ open |foo ]"?
Sorry about the subject line of the post, I intended to post the
following code, but find that when it is called on "cat" for
instance, the timeout code fails strangely.
Interested persons can test like this:
_exec "whois tcltk.org" foo
vwait ::foo
puts $::foo
All sorts of interesting things work, but "_exec cat foo" fails
unexpectedly, the timeout occurs, but the code does not do what
I expect.
proc _exec { prog var { tmpfile "" } { i 0 } { to 5 } } {
if { ! [ regexp {^file\d+$} $prog ] } {
set tmpfile _exec-[ clock seconds ][ clock clicks ]
set tmpfile /tmp/$tmpfile
if { [ catch {
set fid [ open "|$prog 2>$tmpfile" ]
fconfigure $fid -blocking off
fconfigure $fid -buffering full
} err ] } {
file delete -force $tmpfile
return -code error "_exec: $err"
}
} else {
set fid $prog
}
set ret [ read $fid ]
if { ($i / 10) >= $to } {
if { ! [ string length $ret ] } {
set ret timed_out
}
}
if { [ string length $ret ] || [ file size $tmpfile ] } {
catch { ::close $fid }
set fid [ open $tmpfile r ]
set err [ read $fid [ file size $tmpfile ] ]
catch { ::close $fid }
file delete -force $tmpfile
set ::$var [ list $ret $err ]
} else {
incr i
after 100 [ list _exec $fid $var $tmpfile $i ]
}
}
>In THAT case, how do I get the pid of the process opened by
>"set fid [ open |foo ]"?
pid $fid
--
David Gravereaux <davy...@pobox.com>
Tomasoft Engineering, Hayward, CA
But there's nothing you can really do with this information, other
than maybe "exec kill [pid $fid]". But on systems that don't have
"kill", like Win32, you're stuck.
For one software of mine, I include a third-party kill program into
the Win32 distribution, just so that I can exec it.
Wouldn't it be nice if there was a kill in the Tcl core?
Frank
--
Frank Pilhofer ........................................... f...@fpx.de
Even the man who has everything is envious of the man who has two of
everything. - Alfred E. Neuman
Which means I will never be stuck ;^)
Now, should the pipe be closed first or the process killed
first to get the maximum usable info about what happened...