Perl学习笔记的最后一部分,也许是Perl最重要的内容之一,系统命令的调用。
#!/usr/bin/perl
use strict;
use warnings;
use v5.10; # for say() function
my @args;
# say "[INFO ] Clear Dumpfile.\n";
# @args = ("rm DumpDatabase.bk.gz > 1.log 2>&1");
# system(@args) == 0
# or say "No DumpDatabase file : $?";
# say "[INFO ] Dump database to file.\n";
# @args = ("mysqldump -u root expdf_cloud > DumpDatabase.bk");
# system(@args) == 0
# or die "Mysqldump failed: $?";
# say "[INFO ] zip Dumpfile.\n";
# @args = ("gzip -9 DumpDatabase.bk");
# system(@args) == 0
# or die "Gzip failed: $?";
# 第1种调用方式
say "[INFO ] CommondLine WAY1";
@args = ("dir");
system(@args) == 0
or say "No DumpDatabase file : $?";
# 第2种调用方式
say "[INFO ] CommondLine WAY2";
my $res = `dir`;
say $res;
# 第3种调用方式
say "[INFO ] CommondLine WAY3";
open( my $fh, "dir |") or die "$!";
while ( <$fh> ) {
print;
}