system反引號exec
perl也可以用system調用shell的命令,它和awk的system一樣,返回值也是它調用的命令的退出狀態.
[root@AX3sp2 ~]# cat aa.pl#! /usr/bin/perl -w$file = "wt.pl";system("ls -l wt.pl");$result = system "ls -l $file";反引號perl的system函數和awk的一樣不能夠返回命令的輸出. 要得到命令的輸出,就得使用和shell本身一樣的命令: ` `
[root@AX3sp2 ~]# cat bb.pl#! /usr/bin/perlprint `date`;print "this is test /n";[root@AX3sp2 ~]# perl bb.pl2010年 12月 16日 星期四 15:51:59 CSTthis is test最后,perl還可以使用exec來調用shell的命令. exec和system差不多,不同之處在于,調用exec之后,perl馬上就退出,而不會去繼續執行剩下的代碼
[root@AX3sp2 ~]# cat cc.pl#! /usr/bin/perlexec ("echo this is test");print "good bye !/n"; #這句話不會被輸出[root@AX3sp2 ~]# perl cc.plthis is test新聞熱點
疑難解答
圖片精選