Perl运行其他程序的5种方法
2017-05-03 16:32
218 查看
转自:http://www.cnblogs.com/tobecrazy/p/perl.html
1.使用system函数 运行成功,返回0,运行失败则返回非负整数
system(“cmd”);
2.使用qx
my $cmd1=qx/date/;
3.使用“ 与qx等效
4.使用open函数
open(CMD,“ifconfig |”) or die $!
my @result=;
close(CMD);
5.使用readpipe函数
使用readpipe函数可以获取外部程序运行的结果,比如运行 ls 会列出当前目录的文件和文件夹,
my $result=readpipe(“ls “);
1.使用system函数 运行成功,返回0,运行失败则返回非负整数
system(“cmd”);
2.使用qx
my $cmd1=qx/date/;
3.使用“ 与qx等效
4.使用open函数
open(CMD,“ifconfig |”) or die $!
my @result=;
close(CMD);
5.使用readpipe函数
使用readpipe函数可以获取外部程序运行的结果,比如运行 ls 会列出当前目录的文件和文件夹,
my $result=readpipe(“ls “);
#!/usr/bin/perl use strict; my $return=system("date"); print "this is system function , successful:return $return\n"; $return=system("not_exist"); print "this is sysyem function failed,return $return\n"; #use qx my $cmd1=qx/pwd/; print "this time use qx $cmd1"; #qx=`` my $cmd2=`pwd`; print "this time use \`\` $cmd2 "; open(CMD,"echo \"\$(date +\%Y\%m\%d)\"|") or die $!; my @result=<CMD>; close(CMD); print @result; my $result=readpipe("ls -rtl"); print $result;
相关文章推荐
- perl运行其他程序的5种方法
- VC程序中运行其他程序的三种方法(转)
- VC程序中运行其他程序的三种方法
- 5种运行程序的方法具体应用实例(带参数)
- 基于VSCode环境的三种使用Python运行其他程序方法
- C# .NET Winform等程序一运行就闪退 不同环境 换到其他电脑,例如XP之类的解决方法。
- MFC 程序不依赖.NET的设置方法 使自己写的程序可以在其他上电脑运行
- Perl调用其他程序方法
- BCB编译成功的程序在其他机子上运行时提示vcl60.bpl找不到的解决方法
- VC++ 提高C++程序运行效率10个简单方法(其他语言程序参考)
- VC程序中运行其他程序的三种方法
- DELPHI 5种运行程序的方法具体应用实例(带参数)
- 让程序只运行一个实例的5种方法
- python运行其他程序的实现方法
- Perl中调用其他程序的方法
- Perl 调用其他程序方法
- vc程序中运行其他程序和创建文件夹的方法:
- 把java编的程序包装成其他机器windows下可运行的exe
- 在java程序中执行dos命令或运行其他程序
- 让程序在Windows CE系统启动时自动运行-两种方法