Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see stderr output in linux

Tags:

linux

perl

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.

like image 695
adrian4aes Avatar asked Mar 11 '13 17:03

adrian4aes


2 Answers

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

like image 156
Gilles Quenot Avatar answered Oct 13 '22 23:10

Gilles Quenot


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
like image 35
Quentin Avatar answered Oct 13 '22 22:10

Quentin