Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-27-2010
Registered User
 
Join Date: Aug 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
How to redirect the STDERR to a variable in perl?

in my perl script

i tried the below statement

Code:
$result = `cleartool  rmstream -f $s1 1> /dev/null`;

so as to redirect then error messages,when i print the $result

,it seems to be Null.

Last edited by radoulov; 08-27-2010 at 06:27 AM.. Reason: Please use code tags!
Sponsored Links
    #2  
Old 08-27-2010
Registered User
 
Join Date: Aug 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

Code:
$result = `cleartool rmstream -f $s1 2> /dev/null`;


Last edited by radoulov; 08-27-2010 at 06:27 AM.. Reason: Please use code tags!
Sponsored Links
    #3  
Old 08-27-2010
Registered User
 
Join Date: Aug 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
You are jus redirecting the stderr to /dev/null, i want the error message to be stored in a variable
    #4  
Old 08-27-2010
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,338
Thanks: 143
Thanked 1,754 Times in 1,591 Posts
Try:

Code:
$result = `cleartool  rmstream -f $s1 2>&1 >/dev/null`;

Sponsored Links
    #5  
Old 08-27-2010
radoulov's Avatar
--
 
Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 5,468
Thanks: 139
Thanked 538 Times in 506 Posts
And you can get a more detailed explanation in the FAQ:

Quote:
perldoc.perl.org/perlfaq8.html#How-can-I-capture-STDERR-from-an-external-command?
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Redirect just stderr to a file with a timestamp mbak UNIX for Dummies Questions & Answers 5 10-15-2008 01:17 AM
How to redirect stderr and stdout to a file sushantnirwan Shell Programming and Scripting 8 08-28-2008 09:23 AM
can't redirect stderr in bash lumix Shell Programming and Scripting 3 12-16-2007 03:28 AM
how to redirect stderr from top with csh umen Shell Programming and Scripting 2 02-23-2007 12:19 AM
Redirect stdout and stderr zcurtis Shell Programming and Scripting 8 09-02-2002 06:13 AM



All times are GMT -4. The time now is 10:37 PM.