Reputation: 1798
The main question of my current task is to start process from Tcl environment (using exec cmd.) with I/O redirection to parent process (Tcl) and when parent process unexpectedly stopped I'd like to automatically stop the child process. But there is a caveat: for I/O redirection case child process doesn't stop. The problem is complexed because child process can't be modified.
I've found the next thread How to make child process die after parent exits? where solution has been found for C language and without I/O redirection.
So for example, I use the next command in Tcl:
exec ping $SERVER_NAME >@ stdout 2>@ stderr
This command redirect output of stdout and stderr to the parent process (Tcl). But I need to run something like that:
exec sh -c "set -o monitor; ping $SERVER_NAME >@ stdout 2>@ & read dummy; kill %1"
And in the command above output of stdout and stderr goes into "sh" process but I'd like to get it in my parent process. So I have the several question:
Upvotes: 0
Views: 291
Reputation: 137767
The meaning of >@ stdout
is to send the output of the command to the Tcl process's standard out without collecting it. The meaning of 2>@ stderr
is to send the standard error stream of the command to the Tcl process's standard error without collecting it (if it collected something non-empty, it would lead to an error). Thinking about replicating that in a subprocess invokation, even in bash, makes my head hurt! I suspect that you can't quite do it that way.
It's probably easier to do your processing like this:
set pid [exec exec ping $SERVER_NAME >@ stdout 2>@ stderr &]
# and when you want to stop it...
exec kill $pid
Doing a more complete job will require using, say, the TclX package's signal
command.
Upvotes: 0