PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > printf "hi\000"|egrep hi #why no STDERR output
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

printf "hi\000"|egrep hi #why no STDERR output

Réponse
 
LinkBack Outils de la discussion
Vieux 22/04/2008, 14h38   #1
Name withheld by request
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut printf "hi\000"|egrep hi #why no STDERR output

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
~ $

  Réponse avec citation
Vieux 22/04/2008, 14h46   #2
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: printf "hi\000"|egrep hi #why no STDERR output

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
  Réponse avec citation
Vieux 22/04/2008, 15h44   #3
Kenny McCormack
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: printf "hi\000"|egrep hi #why no STDERR output

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.

  Réponse avec citation
Vieux 22/04/2008, 15h58   #4
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: printf "hi\000"|egrep hi #why no STDERR output

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
  Réponse avec citation
Vieux 22/04/2008, 16h40   #5
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: printf "hi\000"|egrep hi #why no STDERR output

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.

  Réponse avec citation
Vieux 22/04/2008, 17h35   #6
Kenny McCormack
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: printf "hi\000"|egrep hi #why no STDERR output

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.

  Réponse avec citation
Vieux 22/04/2008, 22h00   #7
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: printf "hi\000"|egrep hi #why no STDERR output

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.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 09h10.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16874 seconds with 15 queries