Re: Killing a running process
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: Killing a running process

From: Bruce Hartweg <bruce-news@hartweg.us>
Date: Fri Mar 03 2006 - 21:09:16 CET

al-s wrote:
> OK. This is what I tried and I get an error: can't read "pids": no
> such variable. The log reads the above plus: wile executing
> "kill-proc $pids"
> (command bound to event)
>
> Code is as follows:
>
> proc RunCmd {command log} {
> if [catch {open "|$command |& cat"} fd] {
> $log insert end $fd\n
> } else {
> set pids [pid $fd]
> bind $log <Control-Key-c> {kill-proc $pids}

         bind $log <Control-Key-c> [list kill-proc $pids]

you want to use list here so that $pids is interpreted *now*
while that variable is in scope - the way you had it, with {...},
prevents substitution so when the user hit Ctrl-C is when it
tried to substitute the variable which didn't exists then.

> fileevent $fd readable [list Logger $fd $log]
> vwait done
> }
> }
>
> proc kill-proc {pids} {
> catch {exec kill $pids}
> }
>
> Can someone see if I'm doing something wrong - it looks right. But If
> that were true I would have asked for help.
>
> Thanks again
>

bruce
Received on Sun Apr 30 02:23:04 2006