Perl調(diào)用shell命令方法小結(jié)
一、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
二、反引號(hào)
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馬上就退出,而不會(huì)去繼續(xù)執(zhí)行剩下的代碼
[root@AX3sp2 ~]# cat cc.pl
#! /usr/bin/perl
exec ("echo this is test");
print "good bye !\n"; #這句話不會(huì)被輸出
[root@AX3sp2 ~]# perl cc.pl
this is test
- perl批量查詢ip歸屬地的方法代碼
- perl中my和our的區(qū)別分析
- 解析posix與perl標(biāo)準(zhǔn)的正則表達(dá)式區(qū)別
- Perl中的正則表達(dá)式介紹
- 為Java程序員準(zhǔn)備的10分鐘Perl教程
- Perl內(nèi)置特殊變量總結(jié)
- Perl Sort函數(shù)用法總結(jié)和使用實(shí)例
- perl 文件測(cè)試操作符匯總
- Perl使用nginx FastCGI環(huán)境做WEB開發(fā)實(shí)例
- perl查找進(jìn)程PID的例子
- Perl一句話命令行編程中常用參數(shù)總結(jié)
- cpanm安裝及Perl模塊安裝教程
- Windows和Linux系統(tǒng)下perl連接SQL Server數(shù)據(jù)庫(kù)的方法
- 7個(gè)perl數(shù)組高級(jí)操作技巧分享
- Perl函數(shù)(子程序)學(xué)習(xí)筆記
- Perl Substr()函數(shù)及函數(shù)的應(yīng)用
相關(guān)文章
不錯(cuò)的一篇學(xué)習(xí)CGI腳本(腳本)
不錯(cuò)的一篇學(xué)習(xí)CGI腳本(腳本)...2007-07-07關(guān)于Perl里面正則表達(dá)式規(guī)范
關(guān)于Perl正則的一些規(guī)范,很多妙用。2008-10-10perl簡(jiǎn)單變量 整型 浮點(diǎn)數(shù) 字符串
perl簡(jiǎn)單變量 整型 浮點(diǎn)數(shù) 字符串...2007-11-11