tcl:捕获“exec diff”的输出返回非零
我知道在执行可能返回非零的命令时使用 catch 是很常见的...但是在这种情况下如何获得输出?
具体来说,我想做一些类似“catch {exec diff fileA fileB} ret”的事情。文件不同,ret值为1。我实际上需要的是diff的输出,即详细的差异。但我相信“catch {exec ...} err”实践并没有提供它,对吧?
有人可以建议这项任务吗?是否有 tcl 内置命令可以进行文件比较? (我认为可以将输出重定向到文件,然后读取该文件......还有其他选择吗?)
谢谢! XM
I know it is common to use catch when executing commands that may return non-zero... but how can I get the output in that case?
To be specific, I wish to do something like "catch {exec diff fileA fileB} ret". The files are different and ret value is 1. What I actaully need is the output of diff, the detailed differences. But I believe the "catch {exec ...} err" practice does not provide it, right?
Can someone please suggest on this task? Is there tcl-builtin commands to do file diff? (I think it is possible to redirect the output to a file and then read the file... are there any other alternatives?)
Thanks! XM
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自我最近的一个项目:
底线是,当文件不同时,状态为 1,$result 保存 diff 输出。在 diff 输出的末尾,我确实得到了“子进程异常退出”。就我而言,我还没有删除它,但应该很容易做到。
From a recent project of mine:
Bottom line, when the files are different, the status is 1 and $result holds the diff output. At the end of the diff output I do get the "child process exited abnormally". In my case I have not remove it, but it should be easy enough to do.