Writing to stderr.

Writing to stderr.

Post by Harr » Mon, 03 Mar 2003 07:41:32

How do you write to standard error?



Writing to stderr.

Post by Charles Dem » Mon, 03 Mar 2003 08:09:48

>How do you write to standard error?


with gawk I do it like this:

gawk 'BEGIN{print "your message here" > /dev/stderr }'

man gawk

Chuck Demas

  Eat Healthy        |   _ _   | Nothing would be done at all,

  Die Anyway         |    v    | That no one could find fault with it.


Writing to stderr.

Post by William Par » Mon, 03 Mar 2003 08:36:33

>>How do you write to standard error?


> with gawk I do it like this:

> gawk 'BEGIN{print "your message here" > /dev/stderr }'

> man gawk

No, the correct way is :-)
    import sys
    sys.stderr.write("your message here")

man python


Linux solution for data management and processing.


Writing to stderr.

Post by Michael Wa » Mon, 03 Mar 2003 08:40:08

>How do you write to standard error?

ksh: print -u2 whatever
bsh: echo whatever 1>&2
Solaris or whatever system that has /dev/stderr or /dev/fd/2:
  echo >/dev/stderr
Call Perl: perl -e 'print(STDERR whatever)'



Writing to stderr.

Post by Stephane CHAZELA » Mon, 03 Mar 2003 08:50:59


Quote:> with gawk I do it like this:

> gawk 'BEGIN{print "your message here" > /dev/stderr }'

Note that with recent versions of gawk, it actually writes to fd
2 (stderr), with older versions, your system had to have a
/dev/stderr device.

With Bourne like shell:

echo "your message here" >&2

With C shell:

sh -c 'echo "your message here" >&2'

With perl:

perl -le 'print STDERR "your message here"'

With sed, if your system has /dev/stderr or /dev/fd/2:

sed -e 'h;s/.*/your message here/;w /dev/fd/2' -e g

with ruby:

ruby -le 'STDERR.print "your message here"'


python -c 'import sys; sys.stderr.write("your message here\n")'



1. When becoming a daemon, I can't write to stderr?!?!

I'm maintaning a server program here at work, and while trying to fix
some things, I have broken something else. I have broken the ability to
write to my log file. The log file is stderr, just freopen()'ed. ie;
    freopen("mylogfile", stderr);
If I comment out a routine that causes the process to become a daemon,
the redirection of stderr works fine. But, otherwise, the first 10 or so
lines get
printed to the log file, but after that, less and less data actually
makes it to the
log file and then nothing.
The daemon code looks like:
int daemon(int ignsigcld) {
register int childpid, fd;

#ifndef DEBUG
   if(getppid() == 1) /* already a daemon */
      goto out;

#ifdef SIGTTOU
   signal(SIGTTOU, SIG_IGN);
#ifdef SIGTTIN
   signal(SIGTTIN, SIG_IGN);
#ifdef SIGTSTP
   signal(SIGTSTP, SIG_IGN);
#ifndef DEBUG

   if((childpid = fork()) < 0)
      perror("Can't fork first child");
   else if(childpid > 0)
   if(setpgrp() == -1 )
      perror("Can't change process group");
   signal(SIGHUP, SIG_IGN);
   if((childpid = fork()) < 0)
      perror("Can't fork second child");
   else if(childpid > 0)
   /* close all fd except 0 */
   for(fd = 2; fd < NOFILE; fd++)

   errno = 0;
   if(ignsigcld)  {
      signal(SIGCLD, SIG_IGN);
   else {
      signal(SIGCLD, sig_child);

Now, can some one explain to me why I can see data being written to my
log file
when this routine is commented out, but not when it's in???

Frank Kolarek

2. Apache & PHP & HP-UX: Bad Mojo?

3. Having trouble writing to stderr in a csh script

4. Linux 2.4 and ls weirdness

5. Stop write to stderr

6. StorageTek 4280 Tape drives- Help with setup

7. sh - write to stderr

8. ufsrestore/cp a file on usb drive on Solaris 9 produces errors

9. writing to stdout AND stderr

10. Q:how to write things to stderr in a csh script?

11. Nulling a logfile a background process is writing both stdout & stderr to

12. Redirecting stdout and stderr, and stderr

13. stderr & stdout to file and stderr to screen