国产探花免费观看_亚洲丰满少妇自慰呻吟_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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 溧水县| 扶沟县| 新津县| 古丈县| 泾源县| 马公市| 布拖县| 巢湖市| 武乡县| 卫辉市| 剑川县| 宁波市| 阜南县| 嵊泗县| 潜山县| 连云港市| 文成县| 石狮市| 达孜县| 乃东县| 灵宝市| 镇远县| 漠河县| 延长县| 海盐县| 固镇县| 江安县| 兴化市| 阿巴嘎旗| 连平县| 罗江县| 南投县| 蛟河市| 珲春市| 平舆县| 和政县| 襄樊市| 文登市| 航空| 孝感市| 修水县|