For Programmers: Free Programming Magazines  


Home > Archive > AWK > January 2005 > stupid newbie: how to write to standard error?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author stupid newbie: how to write to standard error?
Zhang Weiwu

2005-01-12, 3:55 am

Hello? is there a way to pipe error message to stderr?

My script is often used this way: $awk -f script.awk < infile > outfile
so there is no chance for the user see error message. There must be a
way to write some message to stderr?
William James

2005-01-12, 3:55 am


Zhang Weiwu wrote:
> Hello? is there a way to pipe error message to stderr?
>
> My script is often used this way: $awk -f script.awk < infile >

outfile
> so there is no chance for the user see error message. There must be a


> way to write some message to stderr?


Under unix:
print >"/dev/tty"
Under messydos:
print >"/dev/stderr"



Incidentally, instead of:
awk -f script.awk < infile > outfile
simply say
awk -f script.awk infile > outfile

Ed Morton

2005-01-12, 8:55 am



William James wrote:

> Zhang Weiwu wrote:
>
>
> outfile
>
>
>
>
>
> Under unix:
> print >"/dev/tty"
> Under messydos:
> print >"/dev/stderr"
>


See Aharons reply.

>
> Incidentally, instead of:
> awk -f script.awk < infile > outfile
> simply say
> awk -f script.awk infile > outfile
>


Though I've never needed it myself, there are good reasons to use
"awk ... < infile" rather than "awk ... infile".

The former protects you against file names with characters that awk
wouldn't like to come across in an argument (e.g. an "=" sign). It also
has the shell open the file rather than awk, so if the file can't be
opened, you get the same error message regardless of whether you're
using awk or some other command on that file, and awk won't even be run
(not a huge deal!). The downside is that you lose the automatic setting
of FILENAME or ARGV[1].

So far it hasn't been worth the tradeoff in my environment, but others
have different needs.

Ed.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com