assigning STDERR whild redirecting STDOUT to a file 
Author Message
 assigning STDERR whild redirecting STDOUT to a file

Peter> I would like to be able to exec a command which has STDOUT redirected
Peter> to a file, but I want the STDERR output (if any) to be assigned to a
Peter> variable. Something like:

Peter> $err_msg = exec `snmpwalk $node $object > $file`;

You were real close:

        $err_msg = `snmpwalk $node $object 2>&1 >$file`;

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)

--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying

Web: <A HREF=" http://www.*-*-*.com/ ~merlyn/">My Home Page!</A>



Sun, 07 Dec 1997 03:00:00 GMT  
 assigning STDERR whild redirecting STDOUT to a file

Quote:
>I would like to be able to exec a command which has STDOUT redirected
>to a file, but I want the STDERR output (if any) to be assigned to a
>variable. Something like:
>$err_msg = exec `snmpwalk $node $object > $file`;
>At the end of this I would lie file $file to contain the snmpwalk
>output (no problem), and $err_msg to contain any STDERR output.
>Anybody got any ideas?

How about:

        $err_msg = `snmpwalk $node $object 2>&1 > $file`;

--
Hope this helps,

HansM



Sun, 07 Dec 1997 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Redirecting STDOUT/STDERR to a file

2. redirect stderr and stdout to same file

3. redirect stderr and stdout to the same file

4. how to redirect stderr and stdout to same file

5. HELP - with redirect of STDERR and STDOUT

6. redirect STDERR to STDOUT ?????

7. redirecting stderr and stdout

8. writing to terminal even with STDOUT and STDERR redirected

9. Problem with redirecting STDOUT and STDERR

10. How to redirect STDOUT,STDERR and keep the message order

11. Redirect stderr to stdout w/ Perl under Unix?

12. Redirecting STDERR to STDOUT (on NT)

 

 
Powered by phpBB® Forum Software