How to redirect the STDERR to a variable in perl?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to redirect the STDERR to a variable in perl?
# 1  
Old 08-27-2010
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 07:27 AM.. Reason: Please use code tags!
# 2  
Old 08-27-2010
Code:
$result = `cleartool rmstream -f $s1 2> /dev/null`;


Last edited by radoulov; 08-27-2010 at 07:27 AM.. Reason: Please use code tags!
# 3  
Old 08-27-2010
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
Try:
Code:
$result = `cleartool  rmstream -f $s1 2>&1 >/dev/null`;

# 5  
Old 08-27-2010
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirect STDOUT & STDERR to file and then on screen

Dear all, redirecting STDOUT & STDERR to file is quite simple, I'm currently using: exec 1>>/tmp/tmp.log; exec 2>>/tmp/tmp.logBut during script execution I would like the output come back again to screen, how to do that? Thanks Lucas (4 Replies)
Discussion started by: Lord Spectre
4 Replies

2. Shell Programming and Scripting

How to redirect stderr to a file as well

Hello everyone, I'm a nooby in Linux, and I need some help. I have a shell script like this: echo "Start of script" > ../My_Log_Dir/Script_Name.log .. cp ../My_DataIn/File.txt ../My_DataOut/ 2>> ../My_Log_Dir/Script_Name.log rc=$? .. echo "End of Script" >>... (5 Replies)
Discussion started by: H.Faria
5 Replies

3. Red Hat

Redirect STDOUT and STDERR of chsh

EDIT: Nevermind, figured it out! Forgot to put backslashes in my perl script to not process literals! Hi everyone. I am trying to have this command pass silently. (no output) chsh -s /bin/sh news Currently it outputs. I've tried.... &> /dev/null 1> /dev/null 2>&1 /dev/null 1>&2... (1 Reply)
Discussion started by: austinharris43
1 Replies

4. Shell Programming and Scripting

Redirect stdout/stderr to a file globally

Hi I am not if this is possible: is it possible in bach (or another shell) to redirect GLOBALLY the stdout/stderr channels to a file. So, if I have a script script.sh cmd1 cmd2 cmd3 I want all stdout/stderr goes to a file. I know I can do: ./script.sh 1>file 2>&1 OR ... (2 Replies)
Discussion started by: islegmar
2 Replies

5. UNIX for Dummies Questions & Answers

Redirect just stderr to a file with a timestamp

I'm using below command to redirect stderr to a file but I also want to add timestamp to stderr.out to find out the date / time the error occurred. ls -ltr 2>>/tmp/stderr.out Thanks (5 Replies)
Discussion started by: mbak
5 Replies

6. Shell Programming and Scripting

How to redirect stderr and stdout to a file

Hi friends I am facing one problem while redirecting the out of the stderr and stdout to a file let example my problem with a simple example I have a file (say test.sh)in which i run 2 command in the background ps -ef & ls & and now i am run this file and redirect the output to a file... (8 Replies)
Discussion started by: sushantnirwan
8 Replies

7. Shell Programming and Scripting

can't redirect stderr in bash

Consider: #!/bin/sh #this is a shell script in sh (bourne) grep missingfile 2>errout.txt It works from the command line, but keeps producing errors from the script. So how do I redirect in a bash shell...or bourne? (3 Replies)
Discussion started by: lumix
3 Replies

8. Shell Programming and Scripting

how to redirect stderr from top with csh

Hello all im trying to use top program in my csh shell like this : set topResult = `top | grep server.exe` but im facing 2 problems 1.when the top program dont installed in the machine im getting error so can i check in csh if application im using exist 2 the top program gives... (2 Replies)
Discussion started by: umen
2 Replies

9. Shell Programming and Scripting

how can i redirect stderr to file in Make?

Hello all im using tcsh shell on sun Solaris , using the Make utility for compilation i will like to be able to redirect the stderr to file , how can it be done ? (0 Replies)
Discussion started by: umen
0 Replies

10. Shell Programming and Scripting

Redirect stdout and stderr

How can I redirect and append stdout and stderr to a file when using cron? Here is my crontab file: */5 * * * * /dir/php /dir/process_fns.php >>& /dir/dump.txt Cron gives me an 'unexpected character found in line' when trying to add my crontab file. Regards, Zach Curtis POPULUS (8 Replies)
Discussion started by: zcurtis
8 Replies
Login or Register to Ask a Question