TCL:exec egrep“子进程异常退出";

编程入门 行业动态 更新时间:2024-10-25 06:22:51
本文介绍了TCL:exec egrep“子进程异常退出";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在使用 egrep 命令时遇到问题.当我在 tcsh 中执行我的命令时,它运行良好,但是当我从 tcl 脚本或 tclsh 中执行它时,我得到:

I have a problem with egrep command. When I execute my command in tcsh it is working perfect but when I execute it from tcl script or in tclsh, I got:

子进程异常退出

我的 tcl 代码:

exec egrep -i "^(\\\s+)?(tvf::)?LAYOUT\\\s+PATH" test_file

test_file 包含

The test_file contain

LAYOUT PATH "file1" LAYOUT PATH "file2" //LAYOUT FILE "file 3" foo string tvf::LAYOUT PATH "file4" tvf::LAYOUT PATH "file5"

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

大家好,

我做了一些额外的调查,并在 32 位机器上运行这个命令.该命令在 32 位 egrep 下正常工作

I did some additional investigations and run this command also on 32 bit machine. The command works properly with 32 bit egrep

结果:

LAYOUT PATH "file1" LAYOUT PATH "file2" tvf::LAYOUT PATH "file3" tvf::LAYOUT PATH "file3"

文件/bin/egrep*/bin/egrep: 符号链接到`grep'*

file /bin/egrep */bin/egrep: symbolic link to `grep'*

文件/bin/grep*/bin/grep:ELF 32 位 LSB 可执行文件,Intel 80386,版本 1 (SYSV),用于 GNU/Linux 2.2.5,动态链接(使用共享库),剥离*

file /bin/grep */bin/grep: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, dynamically linked (uses shared libs), stripped*

但是当我删除额外的反斜杠时:

But when I remove additional backslashes :

exec egrep -i "^(\s+)?(tvf::)?LAYOUT\s+PATH" test_file

命令返回错误:

子进程异常退出

64 位机器上的 egrep 版本是:

The egrep version on 64 bit machine is:

文件/bin/egrep*/bin/egrep: 符号链接到`grep'*

file /bin/egrep */bin/egrep: symbolic link to `grep'*

文件/bin/grep*/bin/grep:ELF 64 位 LSB 可执行文件,AMD x86-64,版本 1 (SYSV),用于 GNU/Linux 2.6.9,动态链接(使用共享库),用于 GNU/Linux 2.6.9,已剥离*

file /bin/grep */bin/grep: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped*

推荐答案

grep 使用其退出状态来指示匹配项的存在/不存在 (手册页) - 如果没有匹配项,退出状态为 1.Tcl 的 exec 将任何非零退出状态视为异常情况.您需要catch exec 调用,检查catch 的返回值,如果非零检查$errorCode 变量.这里有一个完整的例子:wiki.tcl.tk/exec,点击显示讨论",然后向下滚动到 KBK 的示例.

grep uses its exit status to indicate presence/absence of a match (man page) - if no matches the exit status is 1. Tcl's exec treats any non-zero exit status as an exceptional situation. You need to catch the exec call, check the return value from catch and if nonzero examine the $errorCode variable. A thorough example here: wiki.tcl.tk/exec, click "Show Discussion" and scroll down to KBK's example.

更多推荐

TCL:exec egrep“子进程异常退出";

本文发布于:2023-08-05 05:42:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1303023.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进程   异常   exec   TCL   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!