Roman Kaganovich
Roman Kaganovich

Reputation: 658

TCL: exec egrep "child process exited abnormally"

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*

Upvotes: 5

Views: 28179

Answers (2)

OutputLogic
OutputLogic

Reputation: 409

I had the same error when running the following command:

exec top -b -n 1 -c | egrep lnx64.o/vsimk | wc -l

TCL wasn't happy about forward slash "/" in the grep expression. It got fixed by using "-ignorestderr" switch:

exec -ignorestderr -- top -b -n 1 -c | egrep lnx64.o/vsimk | wc -l.

Upvotes: 1

glenn jackman
glenn jackman

Reputation: 247142

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.

Upvotes: 13

Related Questions