在Perl中读取shell脚本的控制台输出

2 unix shell console perl log4perl

假设我有一个print_error.sh看起来像这样的shell脚本:

#!/usr/bin/bash

echo "ERROR: Bla bla, yada yada."
exit 1
Run Code Online (Sandbox Code Playgroud)

现在我在Perl脚本中,用这个shell脚本调用

system("print_error.sh")
Run Code Online (Sandbox Code Playgroud)

我现在想要读取控制台输出print_error.sh并将其写入Log4perl记录器.

我怎样才能做到这一点?

Rao*_*oul 5

使用反引号:

my $results = `print_error.sh`;
Run Code Online (Sandbox Code Playgroud)

或看到开放:

http://perldoc.perl.org/functions/open.html