如何抑制 TCL 线程的错误/输出?
我创建了一个线程:
set t1 [thread::create]
thread::send $t1 {
proc myProc {command args} {
exec {*}[auto_execok $command] {*}$args >& /dev/null
}
}
然后尝试发送异步命令:
thread::send -async $t1 [list myProc <command args>]
但是命令的错误/输出显示在输出中。 如何隐藏发送到异步线程的命令的错误/输出?
I have created a thread :
set t1 [thread::create]
thread::send $t1 {
proc myProc {command args} {
exec {*}[auto_execok $command] {*}$args >& /dev/null
}
}
And then tried to send an asynchronous command :
thread::send -async $t1 [list myProc <command args>]
But the error/output from the command is getting displayed in output.
How to hide the errors/outputs from the command that is send to the async thread ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是
捕获
错误。请注意,这会使任何问题显着更难以调试!如果您能够识别预期的错误并
尝试
捕获它们,那就更好了,因此意外错误仍然是您看到并必须处理的事情。对于这种特定情况(从 Tcl 的角度来看,这是非常受 I/O 限制的),您最好将
&
添加到exec
调用的末尾,而不是在单独的线程中运行。在不确切知道自己在做什么的情况下,无法确定,但值得考虑。The simplest method is to
catch
the errors.Be aware that this makes any problems significantly more difficult to debug! It's better if you can identify what errors you expect and just
try
to catch them, so unexpected errors are still things you see and have to handle.For this specific case (which is very much I/O-bound from Tcl's perspective) you might be better off just adding
&
to the end of theexec
call and not running in a separate thread. Can't really say for sure without knowing exactly what you're doing, but it is worth considering.