且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从Perl中的外部* nix命令获取STDOUT,STDERR和响应代码

更新时间:2023-11-11 19:44:58

实际上,正确的写法是:

Actually, the proper way to write this is:

#!/usr/bin/perl
$cmd = 'lsss';  
my $out=qx($cmd 2>&1);
my $r_c=$?;
print "output was $out\n";
print "return code = ", $r_c, "\n";

如果没有错误,您将得到一个"0",如果有错误,您将得到一个"-1".

You will get a '0' if no error and '-1' if error.