I have a use case to implement something as below,
I started a exec using (eval exec) in a tcl file,
now my use case has to keep checking for that exec to be killed (or) go out of existance at regular interval and do a particular operation after it is killed.
what i see is when i am using "after" call for the periodic timer it is costlier and hanging up my main exec as I am runinning a while look to check for the exec existance.
I am manually searching for the exec from the list of process that are running,as I dont have a system call which will intimate me when that exec is killed.
Please suggest a better way to deal with the above.
The more idiomatic way to do this is to open a pipe to the program/executable
and monitor its progress via fileevent. There are plenty of examples on the
Wiki of how to do that, but basically:
Whenever the executable writes to standard output or error or terminates,
your Tcl program is notified, that is, the callback procedure you register
with [fileevent] is called. This gives you all the opportunity to check at
regular intervals if it is still there or not.
The pipe (the "|" above) establishes a connection between the external program
and your Tcl program. That way you can get the output from the program (and whether it is at all alive) as it is produced.
As I am starting a exec using [eval exec args] which returns me a PID,so in my case open "|[eval exec args]" will only produce a Tcl Error like : couldn't execute "4112" while executing "open "|[eval exec args]"
On Friday, October 5, 2012 1:08:00 PM UTC+2, arokia.r...@gmail.com wrote:
> As I am starting a exec using [eval exec args] which returns me a PID,so in my case open "|[eval exec args]" will only produce a Tcl Error like : couldn't execute "4112" while executing "open "|[eval exec args]"
> Do you have any suggestions on this.
Definitely :) Use:
set infile [open "|$args"]
set infile [open "|[eval exec $args]"]
The [open] command will start the program with all the arguments you give
all by itself. It is the pipe sign (|) that instructs it to so.
(With the command you used, you start the program, it returns some data and
that data is then regarded by the [open] command as the name of the file
you want to open.)