I am trying to execute a shell command, and capture its output within perl using backticks, and send the output to STDOUT at the same time,
#!/usr/bin/perl
use strict;
use warnings;
my $output = `echo test1 | tee /dev/fd/1`;
print "op : $output";
This works and gives me the output like this,
op : test1
test1
However, when I'm assigning the output of the command to an array instead of a scalar, it does not work as before,
my @output = `echo test1 | tee /dev/fd/1`;
print "op : $output[0]";
This prints the array variable, but not the echo
output,
op : test1
Meaning that the shell command output is not being sent to STDOUT. Can someone explain why this is happening?
Any help much appreciated.