我在使用 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_filetest_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“子进程异常退出";
发布评论