这个
exec
命令一直等到子进程完成后才将控制权返回给您(除非您在后台完全断开连接地运行)。要保持控制,您需要打开管道:
# Not a read pipe since output is redirected
set pipe [open |[list [info nameofexecutable] jtag.tcl >@$file_id] "w"]
您还需要确保另一个进程监听管道何时关闭,或者有其他协议来通知另一端完成。最简单的机制是远程端放置管道(这是它的
stdin
)进入非阻塞模式,并定期检查退出消息。
# Putting the pipe into nonblocking mode
fconfigure stdin -blocking 0
# Testing for a quit message; put this in somewhere it can be called periodically
if {[gets stdin] eq "quit"} {
exit
}
然后,子流程的关闭协议变为
在父进程中
:
puts $pipe "quit"
close $pipe
或者,终止子进程并获取结果:
exec kill [pid $pipe]
# Need the catch; this will throw an error otherwise because of the signal
catch {close $pipe}