使用 tcl 脚本中的 diff 命令捕获错误“子进程异常退出”
在 tcl 脚本中,我使用 diff 命令逐行比较文件
if {[catch {eval exec "diff /tmp/tECSv2_P_HTTP_XHDR_URL_FUNC_12.itcl /tmp/tempReformat"} results]} {
puts "$results"
}
diff 命令的输出已正确获得,但它捕获错误“子进程异常退出”
输出:
==>tclsh diffUsingScript
992c992
< fail "Redirection is not reflected in css messages"
---
> fail "Redirection is not reflected in css messages"
child process exited abnormally
那么,由于获得此错误,所以出了什么问题。我希望 diff 操作在我的 tcl 脚本中没有错误
In tcl script I am using diff command to compare the files line by line
if {[catch {eval exec "diff /tmp/tECSv2_P_HTTP_XHDR_URL_FUNC_12.itcl /tmp/tempReformat"} results]} {
puts "$results"
}
Output of diff command is obtained properly but it catches error 'child process exited abnormally'
Output:
==>tclsh diffUsingScript
992c992
< fail "Redirection is not reflected in css messages"
---
> fail "Redirection is not reflected in css messages"
child process exited abnormally
So whats going wrong due to which this error is obtained. I want diff operation to be error free in my tcl script
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自我的
diff(1)
:“如果输入相同,则退出状态为 0,如果不同,则退出状态为 1,如果出现问题,则退出状态为 2。”由于非零返回是 shell 脚本中报告错误的常用方式,因此 tcl 和 diff 在返回结果的含义上存在分歧。编写 shell 脚本来了解两个文件是否与返回值不同可能真的很方便,但我没有看到任何机制可以从联机帮助页中禁用它。 (我宁愿使用 cmp -q 来获取两个文件是否不同,不确定为什么 diff 人员做出了他们所做的决定。)
但是您可以通过附加 <代码>; true 符合您的命令。
让它工作的更巧妙的方法是仅在退出代码为
2
时出错:diff foo bar ;如果 [ $? -ne 2 ];那么正确;否则为假; fi;
在每次测试后检查不同文件名的结果并
echo $?
以查看哪些文件返回0
(来自true
)以及哪些返回1
(来自false
)。From my
diff(1)
: "Exit status is 0 if inputs are the same, 1 if different, 2 if trouble."Since non-zero returns are the usual way to report errors in shell scripts, tcl and diff disagree on the meaning of the return result. It's probably really convenient for writing shell scripts to know whether or not two files are different from the return value, but I don't see any mechanism to disable that from the manpage. (I'd rather use
cmp -q
for just getting whether or not two files are different, not sure why the diff people made the decision they did.)But you can bludgeon this into working by appending
; true
to your command.A more artful way to make it work would be to error only on an exit code of
2
:diff foo bar ; if [ $? -ne 2 ]; then true ; else false; fi;
Check the results with different filenames and
echo $?
after each test to see which ones are returning0
(fromtrue
) and which ones are returning1
(fromfalse
).在 Tcl 中处理这个问题的方法是:
参见 Tcl Wiki exec 页面上的讨论。
The way to handle this in Tcl is:
See the discussion on the Tcl Wiki exec page.