gpt4 book ai didi

error-handling - 为什么TCL CATCH命令不返回错误?

转载 作者:行者123 更新时间:2023-12-03 07:41:33 28 4
gpt4 key购买 nike

我试图启动一个已编译的代码来处理我编写的TCL脚本所需的大量计算。启动代码时,我正在使用:

if {[catch {exec $cwd/TaubinSmoother &} error_out]} {
if {[string first "couldn" $error_out] != -1} {
puts "TaubinSmoother software could not be located."
exit
} else {
puts "$error_out"
}
}

exec命令执行时,似乎没有错误,但是确实生成了一个错误,因为没有为TaubinSmoother需要运行的共享库正确设置PATH环境。我试过使用:
 proc launch {} {
set error_catch [catch {exec $cwd/TaubinSmoother &} error_out detail]
return $detail
}

set cwd [file dirname [info script]]
set error_out launch
puts "$error_out"

这也行不通,因为我只收到打印到标准输出的“启动”字样。我阅读了 TCL, get full error message in catch command以及有关 catchreturn的更多信息,但是在我的情况下,回答的问题不起作用,手册页上的示例也无济于事。如何获得实际错误以返回到正在运行的脚本,以便可以向 future 的用户警告遇到的问题?

最佳答案

问题1

您的第二次尝试在“未达到您的期望”的意义上失败了,因为该行

 set error_out launch

应该读
 set error_out [launch]

背景:原始形式是将文字字符串“启动”分配给变量 error_out。因此,这就是您看到的打印内容。

问题2

您的 exec在后台模式下运行( &)。因此,您的Tcl脚本不再与后台进程相关联。 exec将仅返回而不会发出任何(背景错误)错误信号。最好使用子句验证的Tcl习惯用法,使用 openfileevent来检查后台进程:

参见 Detect end of TCL background process in a TCL script

关于error-handling - 为什么TCL CATCH命令不返回错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52005470/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com