Reputation: 869
In a script in perl I have the following:
print STDERR "Access error"
I would like know where this message is printed, but I don't know how can I see the Standar error output in LInux.
Upvotes: 12
Views: 104328
Reputation: 386621
Normally, STDOUT and STDERR are both output to your terminal.
$ perl -e'print "foo\n"; print STDERR "bar\n";'
foo
bar
But it's possible to redirect either and both.
$ perl -e'print "foo\n"; print STDERR "bar\n";' 2>stderr.log
foo
$ cat stderr.log
bar
For example, the data sent to STDERR by a CGI script usually ends up in log file specified in the web server's configuration.
It's possible for a program to get information about STDERR on a linux system.
$ perl -e'system "ls -l /proc/$$/fd"' 2>stderr.log |cat
total 0
lrwx------ ... 0 -> /dev/pts/1
l-wx------ ... 1 -> pipe:[210178663] <-- STDOUT is a pipe
l-wx------ ... 2 -> /home/ikegami/stderr.log <-- STDERR is a file
lr-x------ ... 3 -> pipe:[210178668]
Upvotes: 4
Reputation: 185760
Both the standard (STDOUT
) and the error output (STDERR
) are displayed on your (pseudo) terminal.
If you want to trace the outputs :
error log :
./script.pl 2> err.log
standard output log :
./script.pl > out.log
both STDERR
and STDOUT
in the same file :
./script.pl > out.log 2>&1
or with bash :
./script.pl &> out.log
A good tutorial
Upvotes: 23
Reputation:
You need to run the Perl script in a terminal. Depending on whether you have X on your system or not, you could use xterm
or you could use a virtual console (tty1-7
) to run your script. Both stderr
and stdout
are connected to these devices.
Upvotes: 2
Reputation: 944442
It is printed to wherever standard error is set to for your environment.
If you are running it from a console, then it will be mixed in with the standard output and displayed on the console (it won't be redirected if you redirect STDOUT, you have to redirect it separately).
If you are running it from CGI under Apache, then it will be dropped into your error.log file (wherever Apache is configured to save that).
If you are running it from somewhere else… well an exhaustive list is out of scope for Stackoverflow so you should try asking a more specific question ;)
Example of where it might be directed to at the console:
david@raston err $ cat err.pl
#!/usr/bin/env perl
use strict;
use warnings;
use v5.16;
say "out";
say STDERR "error";
~/tmp/err :
david@raston err $ ./err.pl
out
error
~/tmp/err :
david@raston err $ ./err.pl > stdout
error
~/tmp/err :
david@raston err $ ./err.pl 2> stderr
out
Upvotes: 11