Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

stupid newbie: how to write to standard error?
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?

Report this thread to moderator Post Follow-up to this message
Old Post
Zhang Weiwu
01-05-05 08:55 AM


Re: stupid newbie: how to write to standard error?
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


Report this thread to moderator Post Follow-up to this message
Old Post
William James
01-05-05 01:55 PM


Re: stupid newbie: how to write to standard error?
>
>Zhang Weiwu wrote: 
> 

In article <1104912758.831505.259670@z14g2000cwz.googlegroups.com>,
William James <w_a_x_man@yahoo.com> wrote:
>Under unix:
>print  >"/dev/tty"
>Under messydos:
>print >"/dev/stderr"

Not quite.

If you don't care about DOS and you want absolute portability:

print "message" | "cat 1>&2"

If you're using gawk, mawk, or the Bell Labs awk, any OS:

print "message" > "/dev/stderr"

Printing to /dev/tty is incorrect in the case that awk's stderr
has also been redirected, e.g.,

awk -f infile > outfile 2> errfile

HTH.

Arnold
--
Aharon (Arnold) Robbins --- Pioneer Consulting Ltd.	arnold AT skeeve DOT com
P.O. Box 354		Home Phone: +972  8 979-0381	Fax: +1 206 350 8765
Nof Ayalon		Cell Phone: +972 50  729-7545
D.N. Shimshon 99785	ISRAEL

Report this thread to moderator Post Follow-up to this message
Old Post
Aharon Robbins
01-05-05 01:55 PM


Re: stupid newbie: how to write to standard error?

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.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
01-05-05 08:55 PM


Re: stupid newbie: how to write to standard error?
>
>Zhang Weiwu wrote: 
> 

In article <1104912758.831505.259670@z14g2000cwz.googlegroups.com>,
William James <w_a_x_man@yahoo.com> wrote:
>Under unix:
>print  >"/dev/tty"
>Under messydos:
>print >"/dev/stderr"

Not quite.

If you don't care about DOS and you want absolute portability:

print "message" | "cat 1>&2"

If you're using gawk, mawk, or the Bell Labs awk, any OS:

print "message" > "/dev/stderr"

Printing to /dev/tty is incorrect in the case that awk's stderr
has also been redirected, e.g.,

awk -f infile > outfile 2> errfile

HTH.

Arnold
--
Aharon (Arnold) Robbins --- Pioneer Consulting Ltd.	arnold AT skeeve DOT com
P.O. Box 354		Home Phone: +972  8 979-0381	Fax: +1 206 350 8765
Nof Ayalon		Cell Phone: +972 50  729-7545
D.N. Shimshon 99785	ISRAEL

Report this thread to moderator Post Follow-up to this message
Old Post
Aharon Robbins
01-11-05 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:41 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.