Perl调用shell命令方法小结
来源:互联网 发布:收费站车流量数据分析 编辑:程序博客网 时间:2024/06/03 12:29
Makefile中的perl
ENTRY_POINT := $(shell perl -we 'printf("%x\n", $(CONFIG_XIP_PHYS_ADDR) & ~0xff);')
测试makefile
***************************************************************
target: perl
num = 100
result := $(shell perl -we 'printf("0x%x\n", $(num));')
perl:
echo $(result)
#the result is;
#echo 0x64
#0x64
***************************************************************
SYNOPSIS
perl [ -sTtuUWX ] [ -hv ] [ -V[:configvar] ]
[ -cw ] [ -d[t][:debugger] ] [ -D[number/list] ]
[ -pna ] [ -Fpattern ] [ -l[octal] ] [ -0[octal/hexadecimal] ]
[ -Idir ] [ -m[-]module ] [ -M[-]'module...' ] [ -f ]
[ -C [number/list] ] [ -P ] [ -S ] [ -x[dir] ]
[ -i[extension] ]
[ -e 'command' ] [ -- ] [ programfile ] [ argument ]...
If something strange has gone wrong with your program and you're not
sure where you should look for help, try the -wswitch first. It will
often point out exactly where the trouble is.
********************************************************************************
一、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
- Perl调用shell命令方法小结
- Perl调用shell命令方法小结
- Perl调用shell命令方法小结
- Perl调用shell命令方法小结
- Perl调用shell命令方法小结(system/反引号/exec)
- Perl调用shell命令
- Shell中直接调用perl命令
- perl调用shell命令并获取输出
- perl调用shell shell调用perl
- PERL中对SHELL命令的调用细节
- perl脚本调用shell命令后的结果比较总结
- perl调用shell探讨
- 六种调用shell命令的方法
- 【转】Linux Shell历史命令调用方法
- python调用shell命令的方法
- python 调用shell命令三种方法
- ruby调用执行shell命令的方法
- python 调用shell命令三种方法
- c++读书笔记——类的定义
- git ---- Tortoise git -----ppk ---rsa
- 控制浏览器定时刷新、缓存、重定向
- C# 理解泛型
- NYOJ 网络覆盖+数学问题+ceil的使用
- Perl调用shell命令方法小结
- poj2485解题报告
- Asp.Net 用户验证(自定义IPrincipal和IIdentity)
- swift边学边记
- <转>MySQL Cluster (二) --- 单机搭建集群环境
- MySQL优化之——视图
- Domino中的读者域和作者域
- HBase集群数据迁移方案
- H5大会之后,未来指向何方?