2013年3月31日星期日

perl 捕获整个程序输出到out.txt 文件

#!/usr/bin/perl
use strict;
use warnings;
use IO::File;
use Capture::Tiny ':all';
 
my $out_fh = IO::File->new("out.txt", "w+");
my $err_fh = IO::File->new("out.txt", "w+");
 
my $cmd;
my @software = qw {libevent-2.0.17-stable applications proftpd nginx php per_module webadm};  #variable
 
capture {
foreach(@software){
#my $cmd = "wget -t 3 http://lnamp-web-server.googlecode.com/files/$_.tar.bz2 && rm -rf /home/$_ && tar -jxvf $_.tar.bz2 -C /home/ && chown -R nobody.nobody /home/$_";
my $cmd = "wget -t 3 http://cloud.github.com/downloads/libevent/libevent/$_.tar.gz && rm -rf /home/$_ && tar -zxvf $_.tar.gz -C /home && chown -R nobody:nobody /home/$_";
  system($cmd);
}
} stdout => $out_fh, stderr => $err_fh;

没有评论:

发表评论