On 05/13/2012 07:43 AM, Christopher Jordan-Squire wrote:
> Hi--I was playing around with using awk on wc output and discovered
> that when wc prints "wc: DIR: Is a directory", where DIR is the
> appropriate directory name, it doesn't seem to be printing to stdout.
> If I redirect the output of, say, wc -l ./* to a text file with '>'
> then I don't get the "wc: DIRE: Is a directory" statements. That's
> also causing some weird issues when I pipe wc's output to awk.
> 
> I was trying to understand how wc prints the "Is a directory" line.
> But I haven't been able to figure it out after looking through the
> source for 45 minutes. (I'm a very inexperienced C coder, though. So I
> could have missed something easy.) Could anyone tell me what wc is
> doing and where this shows up in the source?
> 
> Thanks,
> Chris JS

While Jim has explained where in the code that "Is a directory" message
is written, I have the feeling that you may still not yet know where
that string is written to ... as you've redirected wc's output to a file
using something like 'wc -l ./* > /tmp/somefile' and you seem to have
expected that message there.

Normal output - i.e. the word count in wc's case - is written to the
standard output stream (aka stdout) which is usually bound to the file
descriptor number 1 and therefore can be redirected using the '>'
operator (which is short for '1>').

Error messages are written to the standard error stream (aka stderr)
which is usually bound to the file descriptor number 2 and therefore
can be redirected using the '2>' operator.

Try
    wc -l . >/tmp/somefile.out 2>/tmp/somefile.err
to see what's going where.

Hope this helps.

Have a nice day,
Berny

Reply via email to