国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Perl > 正文

Perl調用shell命令方法小結

2020-06-04 20:30:50
字體:
來源:轉載
供稿:網友

一、system
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";
print "$result /n"; #輸出命令的退出狀態
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函數和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來調用shell的命令. exec和system差不多,不同之處在于,調用exec之后,perl馬上就退出,而不會去繼續執行剩下的代碼
代碼如下:
[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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 任丘市| 古蔺县| 昌图县| 江阴市| 康平县| 长治市| 祁连县| 文安县| 葫芦岛市| 个旧市| 乌恰县| 调兵山市| 横峰县| 六盘水市| 丰县| 基隆市| 麻城市| 丁青县| 万州区| 孟州市| 蓬莱市| 克拉玛依市| 孝昌县| 和林格尔县| 来凤县| 陆丰市| 谢通门县| 娱乐| 漠河县| 德惠市| 汤原县| 昆明市| 井研县| 长春市| 兴安盟| 柯坪县| 黄平县| 惠安县| 错那县| 高雄县| 海伦市|