内容简介:http://stackoverflow.com/questions/3854651/how-can-i-store-the-result-of-a-system-command-in-a-perl-variable
$cat test.pl
my $pid = 5892;
my $not = system("top -H -p $pid -n 1 | grep myprocess | wc -l");
print "not = $not\n";
$perl test.pl
11
not = 0
$
我想把结果,即11变成一个变量.我怎样才能做到这一点?
:
你很混淆 system() 和 backticks (“)的目的. system()运行命令并返回退出状态信息(作为16位值:低7位是进程死亡的信号,如果有的话,高8位是实际退出值).反引号(“)运行命令并将其发送到STDOUT.
$exit_status = system("mail-users");
$output_string = `ls`;
有很多方法可以从 Perl 执行外部命令.最有意义的是:
> system() :你想执行一个命令,不想捕获它的输出
> exec :你不想返回
调用perl脚本
> backticks :你想捕捉
输出命令
> open :你想要管道命令(as
输入或输出)到您的脚本
http://stackoverflow.com/questions/3854651/how-can-i-store-the-result-of-a-system-command-in-a-perl-variable
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
jQuery
Earle Castledine、Craig Sharkie / SitePoint / 2010-02-28 / USD 39.95
jQuery: Novice to Ninja is a compilation of best-practice jQuery solutions to meet the most challenging JavaScript problems. In this question-and-answer book on jQuery, you'll find a cookbook of ready......一起来看看 《jQuery》 这本书的介绍吧!
CSS 压缩/解压工具
在线压缩/解压 CSS 代码
随机密码生成器
多种字符组合密码