我正在尝试执行shell命令,并使用反引号在perl中捕获其输出,并同时将输出发送到STDOUT,
#!/usr/bin/perl
use strict;
use warnings;
my $output = `echo test1 | tee /dev/fd/1`;
print "op : $output";
这有效,并为我提供了这样的输出,
op : test1
test1
但是,当我将命令的输出分配给数组而不是标量时,它不像以前那样工作,
my @output = `echo test1 | tee /dev/fd/1`;
print "op : $output[0]";
这将打印数组变量,但不打印echo
输出
op : test1
表示shell命令输出未发送到STDOUT。有人可以解释为什么会这样吗?
任何帮助都非常感激。