Code Comments
Programming Forum and web based access to our favorite programming groups.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?
Post Follow-up to this messageZhang 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
Post Follow-up to this message> >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
Post Follow-up to this messageWilliam 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.
Post Follow-up to this message> >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
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.