help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Grep exited abnormally with code 123


From: Andrew Pennebaker
Subject: Re: Grep exited abnormally with code 123
Date: Wed, 17 Apr 2013 18:27:07 -0400

No, I'm using Emacs 24, and grep is reporting matches, but halting early (omitting matches as a result), and signaling 123.

On Apr 16, 2013 5:08 PM, "Bob Proulx" <bob@proulx.com> wrote:
Eli Zaretskii wrote:
> > Andrew Pennebaker wrote:
> > Often, M-x rgrep terminates early with this message in the minibuffer:
> >
> > Grep exited abnormally with code 123
>
> According to this:
>
>  http://superuser.com/questions/197031/grep-exits-abnormally-with-code-123-when-running-rgrep-on-emacs
>
> this is "normal" (well, everything except the message).

It is normal.  It just means that there were no grep hits.  If there
were grep hits then it would exit 0.  No grep hits and it is reporting
123.  It is a grep feature.

You are probably using emacs 23.  Emacs 23 uses find piped to xargs to
run grep.  That is an obsolete way of running it.  Emacs 24 now
defaults to using only find to run grep.  And in 24 if there are no
grep hits the return is captured and "Grep:exit [no match]" is
displayed instead of a non-zero exit code.  Therefore what you are
complaining about is already improved in the next version.

To understand where the 123 comes from start looking at the grep
documentation.

  man grep
  EXIT STATUS
       The  exit  status is 0 if selected lines are found, and 1 if not found.
       If an error occurred the exit status is 2.  (Note: POSIX error handling
       code should check for '2' or greater.)

If there are no matches then grep exits 1.

The xargs command exit status is:

  man xargs
  EXIT STATUS
       xargs exits with the following status:
       0 if it succeeds
       123 if any invocation of the command exited with status 1-125
       124 if the command exited with status 255
       125 if the command is killed by a signal
       126 if the command cannot be run
       127 if the command is not found
       1 if some other error occurred.

       Exit codes greater than 128 are used by the shell to  indicate  that  a
       program died due to a fatal signal.

And since grep exits 1 with no matches then xargs exits 123 as
documented in the above table.

Emacs 23 and earlier:
  find . -type f -print0 | xargs -0 -e grep -nH -e PATTERN

Emacs 24:
  find . -type f -exec grep -nH -e PATTERN {} +

> Perhaps consider submitting a bug report.

Since it has already been addressed with a later version I would
simply update the default grep-find pattern to the new find-only
style.  Then it will be solved now.  Or upgrade to emacs 24. :-)
Or just understand that exit 123 means no grep matches.

You can customize the grep-find-command.  The v24 help for it says:

  grep-find-command is a variable defined in `grep.el'.
  Its value is ("find . -type f -exec grep -nH -e  {} +" . 34)
  Original value was nil

    This variable may be risky if used as a file-local variable.

  Documentation:
  The default find command for M-x grep-find.
  In interactive usage, the actual value of this variable is set up
  by `grep-compute-defaults'; to change the default value, use
  Customize or call the function `grep-apply-setting'.

Bob


reply via email to

[Prev in Thread] Current Thread [Next in Thread]