[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: wc 'Is a directory' output
From: |
Bernhard Voelker |
Subject: |
Re: wc 'Is a directory' output |
Date: |
Mon, 14 May 2012 14:08:44 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120421 Thunderbird/12.0 |
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