TCL: exec egrep “child process exited abnormally”

后端 未结 2 779
挽巷
挽巷 2021-01-03 06:18

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:

c

相关标签:
2条回答
  • 2021-01-03 06:28

    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.

    0 讨论(0)
  • 2021-01-03 06:49

    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.
    
    0 讨论(0)
提交回复
热议问题