如果我运行一个 perl 程序并使用反引号调用另一个 perl 程序,则来自被调用程序的打印语句不会出现在终端上。
如果我使用“系统”调用程序,则会显示打印语句。
例如:这是 ProgA.pl
print "In ProgA.pl, about to call ProgB.pl";
my $dum=`ProgB.pl`; # print output doesn't appear
### $dum=system("ProgB.pl"); # this prints OK
print"\nBack in ProgA.pl";
print "\ndum = $dum"; # ProgB's output doesn't show here either
(没有警告或错误,通过文件关联找到perl.exe)
这是 ProgB.pl:
print "\nPrinting from ProgB.pl";
差异的原因是什么?
为什么 $dum 中没有返回反引号调用输出(我尝试了 STDOUT 和 STDERR)?如果我在反引号中调用 dir,我会在 $dum 中得到它的输出。