Perl调用shell命令方法小结(system/反引号/exec)
来源:互联网 发布:少女前线 妖精数据 编辑:程序博客网 时间:2024/06/05 12:08
- system
- 反引号
- exec
- 为避免shell命令的特殊符号采用先变量定义的方法
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.pl02010年 12月 16日 星期四 15:58:34 CST
反引号
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
exec
最后,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
为避免shell命令的特殊符号,采用先变量定义的方法
qilei@AFAAW-704030720:~$ cat simple.pl#!/usr/bin/perluse strict;use warnings;my $shellcmd="cat test.txt";print `$shellcmd`;qilei@AFAAW-704030720:~$ ./simple.pl test.txta11111a22222a33333a44444a55555a66666a77777a88888a99999a00000b11111b22222b33333b44444b55555b66666b77777b88888b99999b00000qilei@AFAAW-704030720:~$
0 0
- Perl调用shell命令方法小结(system/反引号/exec)
- perl 调用外部命令之system,exec,“反引号
- perl 调用外部命令之system,exec,“反引号
- perl system exec 反引号
- perl中的反引号`` system exec
- 关于perl中的反引号(``),system和exec
- 转载 : 关于perl中的反引号(``),system和exec
- 关于perl中的反引号(``),system和exec
- Perl调用shell命令方法小结
- Perl调用shell命令方法小结
- Perl调用shell命令方法小结
- Perl调用shell命令方法小结
- perl system和exec 调用
- perl中关于system与反引号``的差别
- perl对于反引号(``)以及system之间的不同
- perl中system函数和反引号` `使用区别
- Perl调用shell命令
- Shell 反引号 `
- 阿里云Maven仓库
- python编码声明:是coding:utf-8还是coding=urf-8呢?
- Java反射
- 清除缓存的封装 menglong0329
- 在 Linux 上配置一个 syslog 服务器
- Perl调用shell命令方法小结(system/反引号/exec)
- 每天一题LeetCode[第三天]
- UVa 10474 Where is the Marble? 【STL】【排序与检索-sort和lower_bound】
- 多线程与多进程通信方式的区别
- mysql索引优化
- Wine 2.0 发布!在 Linux 中运行 Microsoft Office 2013 吧
- php写一个冒泡排序
- Spring 杂谈
- 2016数据库技术盘点