Perl运行其他程序的5种方法
发布时间:2020-12-15 23:39:21 所属栏目:大数据 来源:网络整理
导读:转自:http://www.cnblogs.com/tobecrazy/p/perl.html 1.使用system函数 运行成功,返回0,运行失败则返回非负整数 system(“cmd”); 2.使用qx my $cmd1=qx/date/; 3.使用“ 与qx等效 4.使用open函数 open(CMD,“ifconfig |”) or die $! my @result=; clos
转自:http://www.cnblogs.com/tobecrazy/p/perl.html 1.使用system函数 运行成功,返回0,运行失败则返回非负整数 system(“cmd”); 2.使用qx my $cmd1=qx/date/; 3.使用“ 与qx等效 4.使用open函数 open(CMD,“ifconfig |”) or die $! my @result=; close(CMD); 5.使用readpipe函数 使用readpipe函数可以获取外部程序运行的结果,比如运行 ls 会列出当前目录的文件和文件夹, my $result=readpipe(“ls “); #!/usr/bin/perl
use strict;
my $return=system("date");
print "this is system function,successful:return $returnn";
$return=system("not_exist");
print "this is sysyem function failed,return $returnn";
#use qx
my $cmd1=qx/pwd/;
print "this time use qx $cmd1";
#qx=``
my $cmd2=`pwd`;
print "this time use `` $cmd2 ";
open(CMD,"echo "$(date +%Y%m%d)"|") or die $!;
my @result=<CMD>;
close(CMD);
print @result;
my $result=readpipe("ls -rtl");
print $result;
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |