Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-24-2011, 12:41 PM   #1
LQ Newbie
Registered: Nov 2011
Posts: 29

Rep: Reputation: Disabled
Perl: redirect STDERR from system() call to /dev/null

Hello everybody,
I am doing some finishing touches to my perl script that is used to telnet into devices and issue some commands.

the problem is that after cold boot some of my devices create slightly different output than after issuing the commands one more time (this is due to different version of system running and I cannot change because they don't have enough resources to run the newer version (that runs on most of my devices and produces output that works fine with my script))

so what I want to do is to run my perl script and redirect all the STDOUT and STDERR to /dev/null and then run my script for the 2nd time and this time it produces valid results and I want to see all the STDOUT and possible STDERR

since the script is the same I would like to perform it via redirection and via modification of my script or having 2 scripts

I cannot fully disclose of that script but it is not necessary I think

in my script I use some "native perl commands" as well as using system() call to execute external shell scripts

when executing the script like this
perl ./ > /dev/null 2 > /dev/null
I achieve redirection of STDOUT and STDERR to /dev/null but only for "native perl commands"

error messages from system() calls are still shown
is there a way of redirecting STDERR from system() as well?

the commands executed using system() are grep and another shell script

any advices are appreciated.
thank you very much in advance

actually I only want to suppress STDERR from another shell script (that shell script is calling grep)
any ideas?

//I tried to simulate the issue on my local Linux host (unfortunately I cannot verify it with those devices)
instead of calling it like this ()
perl ./ > /dev/null 2 > /dev/null
I tried calling my local sample like this
perl ./ > /dev/null 2> /dev/null
and now it does not print anything to STDERR

was it that single space in 2 > /dev/null that ruined my attempts to succeed?
I will try it tomorrow but if anybody more experienced could tell me if that new redirection will discard any STDOUT and STDERR messages that my perl script produces

thanks in advance

Last edited by totaluser; 11-24-2011 at 02:34 PM. Reason: I reviewed my script and I was not accurate enough
Old 11-24-2011, 09:13 PM   #2
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,565

Rep: Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425
Really need to see how you are calling the other cmds from within Perl in order to help.
If those parts of the Perl prog contain any passwds etc, just replace with 'XXX' when you show us it.
Just need the code around the external calls really.
Old 11-25-2011, 03:30 AM   #3
LQ Newbie
Registered: Nov 2011
Posts: 29

Original Poster
Rep: Reputation: Disabled

the code looks like this

some for loop here using only perl commands

system("bash", "./") == 0 or die "error ###" ;

some other perl commands that don't get executed when script dies
I just tested it today
calling it like this
perl ./ 1>/dev/null 2>/dev/null
achieves exactly what I wanted, no output to STDOUT or STDERR from either my perl script or external commands that my script is calling

It was that space in 2 > /dev/null that caused it not to work


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl stderr&stdout redirect question Fredde87 Programming 5 03-26-2009 05:43 AM
How to get stderr output when using a ::system() call tmc3011 Programming 2 01-25-2008 05:17 AM
What is meant by " file > /dev/null 2>&1 </dev/null " attockonian Linux - Newbie 5 06-30-2006 11:51 PM
redirecting stdout to /dev/null and stderr to stdout? Thinking Programming 1 05-18-2006 03:36 AM
Redirect X windows / GUI to /dev/null? mattfr Linux - Software 9 12-20-2004 10:40 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:39 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration