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

首頁 > 編程 > Perl > 正文

Perl調用shell命令方法小結

2020-10-31 15:16:43
字體:
來源:轉載
供稿:網友

一、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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 启东市| 湛江市| 固始县| 香格里拉县| 平阳县| 武平县| 平度市| 潞城市| 连州市| 宕昌县| 青浦区| 蒲江县| 威宁| 新龙县| 玛沁县| 昌江| 房产| 称多县| 钟祥市| 高安市| 长海县| 通道| 天祝| 延长县| 庄河市| 海林市| 伊宁市| 和平县| 离岛区| 永川市| 永年县| 江阴市| 台中市| 鹿泉市| 永寿县| 紫金县| 封开县| 平罗县| 高安市| 方城县| 桂东县|