LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-09-2015, 02:13 AM   #1
gaurav_s
Member
 
Registered: Jul 2014
Posts: 43

Rep: Reputation: Disabled
Redirecting standard error in perl script to /dev/null


In a perl script i am executing below command.
whenever $pName is empty it ,program is printing some error message . I don't want to print those error message ,so i am using >/dev/null 2>&1 as below. But, still i am getting error message.

my $procID=`ps -ef | grep $pName | grep -v grep |awk '{print \$2}' | head -1 >/dev/null 2>&1 ` ;

Please suggest better way to achieve this.
 
Old 01-09-2015, 02:27 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 20,252

Rep: Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836
yes. that redirection will redirect the output of head, not the grep inside.
I can only suggest you to drop that line and implement it in perl (as you use perl already)
Code:
open (PS, "ps -ef") or die;
while ( <PS> )
{
    # evaluate things here
}
close PS;
Another tip is to avoid finding procID if pName is empty (do not execute that line at all).
 
Old 01-12-2015, 03:15 AM   #3
gaurav_s
Member
 
Registered: Jul 2014
Posts: 43

Original Poster
Rep: Reputation: Disabled
Thanks a lot
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Perl: redirect STDERR from system() call to /dev/null totaluser Linux - Newbie 2 11-25-2011 02:30 AM
Bash script: catch file not found error and send to /dev/null noir911 Programming 7 04-24-2010 08:37 PM
I got a question about redirecting to /dev/null trist007 Linux - Newbie 3 12-13-2009 06:34 PM
Redirecting a desktop-oriented program's mandatory X output to /dev/null for a server srunni Linux - Server 3 07-16-2008 05:16 PM
redirecting stdout to /dev/null and stderr to stdout? Thinking Programming 1 05-18-2006 02:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:45 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration