Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

sqldatasource dal, wwwxxxenden, convert raid5 to raid 10 mdadm, apache force chunked, nrao wwwxxx, xxxxxdup, procmail change subject header, wwwXxx not20, Wwwxxx.doks sas, linux raid resync after reboot

Links

XODOX
Impressum

#1: printf "hi/000"|egrep hi #why no STDERR output

Posted on 2008-04-22 15:38:33 by anonb6e9

I do not understand why 'Binary file (standard input) matches' goes
to STDOUT, why not to STDERR?:

~ $ date;uname -sr
Tue Apr 22 08:35:42 CDT 2008
Linux 2.6.5-1.358
~ $ printf "hi\000"|egrep hi >foo
~ $ cat foo
Binary file (standard input) matches
~ $

Report this message

#2: Re: printf "hi/000"|egrep hi #why no STDERR output

Posted on 2008-04-22 15:46:58 by Stephane CHAZELAS

2008-04-22, 13:38(+00), Name withheld by request:
> I do not understand why 'Binary file (standard input) matches' goes
> to STDOUT, why not to STDERR?:
>
> ~ $ date;uname -sr
> Tue Apr 22 08:35:42 CDT 2008
> Linux 2.6.5-1.358
> ~ $ printf "hi\000"|egrep hi >foo
> ~ $ cat foo
> Binary file (standard input) matches
> ~ $

Maybe because it's not an error.

--
Stéphane

Report this message

#3: Re: printf "hi/000"|egrep hi #why no STDERR output

Posted on 2008-04-22 16:44:37 by gazelle

In article <slrng0rr2i.7b0.stephane.chazelas@spam.is.invalid>,
Stephane CHAZELAS <this.address@is.invalid> wrote:
>2008-04-22, 13:38(+00), Name withheld by request:
>> I do not understand why 'Binary file (standard input) matches' goes
>> to STDOUT, why not to STDERR?:
>>
>> ~ $ date;uname -sr
>> Tue Apr 22 08:35:42 CDT 2008
>> Linux 2.6.5-1.358
>> ~ $ printf "hi\000"|egrep hi >foo
>> ~ $ cat foo
>> Binary file (standard input) matches
>> ~ $
>
>Maybe because it's not an error.

And maybe the sun rises in the east.

And yet you can see where he is coming from. In some sense, the term
"standard error" is a misnomer. It really is/should be "Out of Band".

Really, the standard error channel should be used for any OOB type
information - that is, other than the actual, genuine output of the command.

Report this message

#4: Re: printf "hi/000"|egrep hi #why no STDERR output

Posted on 2008-04-22 16:58:12 by Stephane CHAZELAS

2008-04-22, 14:44(+00), Kenny McCormack:
[...]
>>> ~ $ printf "hi\000"|egrep hi >foo
>>> ~ $ cat foo
>>> Binary file (standard input) matches
>>> ~ $
>>
>>Maybe because it's not an error.
>
> And maybe the sun rises in the east.
>
> And yet you can see where he is coming from. In some sense, the term
> "standard error" is a misnomer. It really is/should be "Out of Band".
>
> Really, the standard error channel should be used for any OOB type
> information - that is, other than the actual, genuine output of the command.

In which way isn't the "Binary file (..." message "actual,
genuine output of grep"? It seems to me that it carries
information requested by the user (can "hi" be found in the
standard input?).

--
Stéphane

Report this message

#5: Re: printf "hi/000"|egrep hi #why no STDERR output

Posted on 2008-04-22 17:40:36 by Bill Marcum

On 2008-04-22, Name withheld by request <anonb6e9@nyx3.nyx.net> wrote:
>
>
> I do not understand why 'Binary file (standard input) matches' goes
> to STDOUT, why not to STDERR?:
>
> ~ $ date;uname -sr
> Tue Apr 22 08:35:42 CDT 2008
> Linux 2.6.5-1.358
> ~ $ printf "hi\000"|egrep hi >foo
> ~ $ cat foo
> Binary file (standard input) matches
> ~ $
>
It's normal for (e)grep to produce output if it finds a match. If the
input were not considered binary, the matching line(s) would be output.
You can use the -a option to force *grep to treat its input as plain
text, or you can pipe the output of strings to *grep if you don't want
strange things to happen to your terminal.

Report this message

#6: Re: printf "hi/000"|egrep hi #why no STDERR output

Posted on 2008-04-22 18:35:33 by gazelle

In article <slrng0rv84.7t9.stephane.chazelas@spam.is.invalid>,
Stephane CHAZELAS <this.address@is.invalid> wrote:
>2008-04-22, 14:44(+00), Kenny McCormack:
>[...]
>>>> ~ $ printf "hi\000"|egrep hi >foo
>>>> ~ $ cat foo
>>>> Binary file (standard input) matches
>>>> ~ $
>>>
>>>Maybe because it's not an error.
>>
>> And maybe the sun rises in the east.
>>
>> And yet you can see where he is coming from. In some sense, the term
>> "standard error" is a misnomer. It really is/should be "Out of Band".
>>
>> Really, the standard error channel should be used for any OOB type
>> information - that is, other than the actual, genuine output of the command.
>
>In which way isn't the "Binary file (..." message "actual,
>genuine output of grep"?

The answer to that is obvious. You may not agree with it, but feigning
ignorance is not going to win you any points.

>It seems to me that it carries information requested by the user (can
>"hi" be found in the standard input?).

I see where you're going with this - but the point is that if you are
looking for a yes/no answer, you should be using the return status of
grep as your indicator, not trying to parse the output.

Report this message

#7: Re: printf "hi/000"|egrep hi #why no STDERR output

Posted on 2008-04-22 23:00:27 by Ed Morton

On 4/22/2008 9:58 AM, Stephane CHAZELAS wrote:
> 2008-04-22, 14:44(+00), Kenny McCormack:
> [...]
>
>>>> ~ $ printf "hi\000"|egrep hi >foo
>>>> ~ $ cat foo
>>>> Binary file (standard input) matches
>>>> ~ $
>>>
>>>Maybe because it's not an error.
>>
>>And maybe the sun rises in the east.
>>
>>And yet you can see where he is coming from. In some sense, the term
>>"standard error" is a misnomer. It really is/should be "Out of Band".
>>
>>Really, the standard error channel should be used for any OOB type
>>information - that is, other than the actual, genuine output of the command.
>
>
> In which way isn't the "Binary file (..." message "actual,
> genuine output of grep"? It seems to me that it carries
> information requested by the user (can "hi" be found in the
> standard input?).
>

I think the information the user wanted was "the line where hi occurs in the
standard input". If they just wanted to know "can hi be found..." they'd have
used the -l or similair option to suppress printing the matching text.

Having said that, yes, I know this is how grep's designed and to get the output
from a binary file that you're used to getting otherwise would require "-a" (at
least with GNU grep) and I expect there's good reasons for it, but this:

$ printf "hi"| grep hi
hi
$ printf "hi"| grep -l hi
(standard input)
$ printf "hi\000"| grep hi
Binary file (standard input) matches
$ printf "hi\000"| grep -a hi
hi
$ printf "hi\000"| grep -a -l hi
(standard input)

isn't exactly intuitively obvious or consistent!

Ed.

Report this message