How do you write to standard error?
Thanks
>Thanks
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.
>>Thanks
> with gawk I do it like this:
> gawk 'BEGIN{print "your message here" > /dev/stderr }'
> man gawk
man python
--
Linux solution for data management and processing.
--
Note that with recent versions of gawk, it actually writes to fdQuote:> with gawk I do it like this:
> gawk 'BEGIN{print "your message here" > /dev/stderr }'
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:
python -c 'import sys; sys.stderr.write("your message here\n")'
--
Stphane
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;
#endif
#ifdef SIGTTOU
signal(SIGTTOU, SIG_IGN);
#endif
#ifdef SIGTTIN
signal(SIGTTIN, SIG_IGN);
#endif
#ifdef SIGTSTP
signal(SIGTSTP, SIG_IGN);
#endif
#ifndef DEBUG
if((childpid = fork()) < 0)
perror("Can't fork first child");
else if(childpid > 0)
_exit(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)
_exit(0);
out:
/* close all fd except 0 */
for(fd = 2; fd < NOFILE; fd++)
close(fd);
#endif
errno = 0;
umask(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
6. StorageTek 4280 Tape drives- Help with setup
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