执行shell命令不会产生任何结果

我在我的Perl脚本中运行shell命令,但它不能按预期工作。 我在一个高山Linux的容器作为我的基本形象。

我的Perl版本v5.24.0。

perl -e 'my $TEST = `ls -al`; print $TEST' 

这不会打印任何东西,但可以在Red Hat Linux上的Perl v5.6.1的另一个系统上运行。

可能是你的问题。

我想你没有定义PATH env var。

尝试使用ls (/ bin / ls)的完整path:

 perl -e 'my $TEST = `/bin/ls -al`; print $TEST' 

我testing过类似的情况:

清空path:

 PATH="" /usr/bin/perl -e' my $output = `ls -al`; if (!defined($output)) { die("readpipe: $!\n") if $? == -1; die("Child killed by signal ".( $? & 0x7F )."\n") if $? & 0x7F; die("Child exited with error ".( $? >> 8 )."\n") if $? >> 8; } print($output); ' 

输出:

 readpipe: No such file or directory 

使用绝对path(/ bin / ls):

 PATH="" /usr/bin/perl -e' my $output = `/bin/ls -al`; if (!defined($output)) { die("readpipe: $!\n") if $? == -1; die("Child killed by signal ".( $? & 0x7F )."\n") if $? & 0x7F; die("Child exited with error ".( $? >> 8 )."\n") if $? >> 8; } print($output); ' 

输出:

 total 4531444 drwxr-xr-x 7 rbravo rbravo 4096 May 30 19:40 . drwxr-xr-x 63 root root 4096 Apr 7 14:11 .. -rw------- 1 rbravo rbravo 12248 May 30 19:39 .bash_history ...