LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
LinkBack Search this Thread
Old 11-24-2011, 11:41 AM   #1
totaluser
LQ Newbie
 
Registered: Nov 2011
Posts: 28

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
Code:
perl ./my_script.pl > /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


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

edit:
//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 ()
Code:
perl ./my_script.pl > /dev/null 2 > /dev/null
I tried calling my local sample like this
Code:
perl ./my_script.pl > /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 01:34 PM. Reason: I reviewed my script and I was not accurate enough
 
Old 11-24-2011, 08:13 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5
Posts: 16,076

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 02:30 AM   #3
totaluser
LQ Newbie
 
Registered: Nov 2011
Posts: 28

Original Poster
Rep: Reputation: Disabled
Hi

the code looks like this

Code:
some for loop here using only perl commands

system("bash", "./script.sh") == 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
Code:
perl ./my_script.pl 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
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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


All times are GMT -5. The time now is 11:55 PM.

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