欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Perl調(diào)用shell命令方法小結

 更新時間:2014年05月10日 12:19:49   作者:  
這篇文章主要介紹了Perl調(diào)用shell命令方法小結,需要的朋友可以參考下

一、system
perl也可以用system調(diào)用shell的命令,它和awk的system一樣,返回值也是它調(diào)用的命令的退出狀態(tài).

復制代碼 代碼如下:

[root@AX3sp2 ~]# cat aa.pl
#! /usr/bin/perl -w
$file = "wt.pl";
system("ls -l wt.pl");
$result = system "ls -l $file";
print "$result \n"; #輸出命令的退出狀態(tài)
system "date";

[root@AX3sp2 ~]# perl aa.pl
-rwxr-xr-x 1 root root 126 12-16 15:12 wt.pl
-rwxr-xr-x 1 root root 126 12-16 15:12 wt.pl
0
2010年 12月 16日 星期四 15:58:34 CST     


二、反引號
perl的system函數(shù)和awk的一樣不能夠返回命令的輸出.
要得到命令的輸出,就得使用和shell本身一樣的命令:     ` `
復制代碼 代碼如下:

[root@AX3sp2 ~]# cat bb.pl
#! /usr/bin/perl
print `date`;
print "this is test \n";

[root@AX3sp2 ~]# perl bb.pl
2010年 12月 16日 星期四 15:51:59 CST
this is test


三、exec
最后,perl還可以使用exec來調(diào)用shell的命令. exec和system差不多,不同之處在于,調(diào)用exec之后,perl馬上就退出,而不會去繼續(xù)執(zhí)行剩下的代碼
復制代碼 代碼如下:

[root@AX3sp2 ~]# cat cc.pl
#! /usr/bin/perl
exec ("echo this is test");
print "good bye !\n";  #這句話不會被輸出

[root@AX3sp2 ~]# perl cc.pl
this is test

相關文章

最新評論