Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCL: exec egrep "child process exited abnormally"

Tags:

tcl

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:

child process exited abnormally

My tcl code:

exec egrep -i "^(\\\s+)?(tvf::)?LAYOUT\\\s+PATH" 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"

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

Hello all,

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

Result:

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

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

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

The command return error:

child process exited abnormally

The egrep version on 64 bit machine is:

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

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*

like image 437
Roman Kaganovich Avatar asked Dec 27 '22 01:12

Roman Kaganovich


1 Answers

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: http://wiki.tcl.tk/exec, click "Show Discussion" and scroll down to KBK's example.

like image 186
glenn jackman Avatar answered Feb 07 '23 15:02

glenn jackman