How to capture both STDOUT and STDERR in two different variables using Backticks in Perl

后端 未结 4 1131
陌清茗
陌清茗 2021-02-08 17:15

Let\'s say I want to run an external program from my script with backticks and at the same time I want to capture both STDOUT and STDERR but in two different variables. How can

4条回答
  •  野的像风
    2021-02-08 17:56

    The only way to do this with backticks is to redirect to a file inside the shell command:

       my $cmd = `snmpwalk -v $version -c $community $hostname $oid 2>error.dat`;
    

    If you want to capture the STDERR inside your script, you need IPC::Open3 instead of backticks

提交回复
热议问题