Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl script to capture stderr and stdout of command executed in back-quotes

Tags:

linux

perl

In the following command which I execute in a Perl script, how do I capture stderr?

my $output = `ssh login.com git clone --bare [email protected]:/nfs/repo/ /nfs/repo//4124/`;
if ($? ne '0')
{ 
    $stderr = $output;
    print $stderr;
}
else
{
    $stdout = $output;
    print $stdout;
}
like image 608
Rajeev Avatar asked Nov 18 '25 02:11

Rajeev


1 Answers

You can use Capture::Tiny to capture stdout, stderr or both merged.

like image 193
bvr Avatar answered Nov 20 '25 17:11

bvr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!