2013-01-08 110 views
-1

這裏是我使用的骨架腳本:如何運行的時候一個Perl腳本,N多內的perl腳本

#!/usr/bin/env perl 

=head1 NAME 

webapp-1 harness - webapp-1 test 

=head1 SYNOPSIS 

    webapp-1 [OPTION] 

    -v, --verbose use verbose mode 
    --help   print this help message 

Where OPTION is an integer governing the number of times the script should be run 

Examples: 

    webapp-1 10 

=head1 DESCRIPTION 

This is test harness to verify jira issue WEBAPP-1 

=head1 AUTHOR 

[email protected] 

=cut 

use strict; 
use warnings; 

use Getopt::Long qw(:config auto_help); 
use Pod::Usage; 

my $count = $ARGV; 

main(); 

sub main { 

    # Argument parsing 
    my $verbose; 
    GetOptions(
     'verbose' => \$verbose, 
    ) or pod2usage(1); 
    pod2usage(1)unless @ARGV; 

    while ($count) { 
    printf "$count \n"; 
    # Here i want to run a perl script N number of times, with N being the ARGV to this command 
    # capture([0,1,2, $^X, "yourscript.pl", @ARGS); 
    $count++; 
    } 
} 

我也不能使用IPC ::系統,因爲我不能在主機上安裝它(Ubuntu的12.04)我正在運行它。 什麼,我試圖做的是開發一個Perl的測試功能,這將運行perl腳本運行過程,監控數據庫表,等等,我還可以控制這些腳本的,時機成果的基礎上,我從他們的執行得到。

一個可能的解決方案:用於運行基於@ARGV

foreach (1..$ARGV[0]) 
    { 
     print "hello \n"; 
    } 
+0

看看:http://stackoverflow.com/questions/364842/how-do-i-run-a-perl-script-from-within-a-perl-script?rq=1 – Paul

+0

請可以您是否澄清了安裝模塊時遇到的困難?也許我們可以克服這一點。 「IPC :: System」也是它的確切名稱嗎? [爲其搜索MetaCPAN]時,不會出現該名稱的模塊(https://metacpan.org/search?q=IPC%3A%3ASystem)。 – Smylers

+0

@Smylers它的IPC ::系統::簡單 如果我使用cpanminus,我將不得不根,或具有root權限,安裝模塊,我不能由操作員獲得 – kamal

回答

1

你不需要root權限來安裝CPAN模塊的次劇本N多。

cpanm需要-l選項安裝到指定的目錄下,如~/perl5/

然後在您的程序中使用local::lib模塊將perl指向您安裝模塊的位置。這很簡單,只要:

use local::lib '~/project/lib'; 

,或者,如果你選擇~/perl5/安裝到,簡單地說:

use local::lib; 

兩個CpanMinus和local::lib可引導安裝的非根:

這些一起給你CPAN的力量,而不需要從服務器的SYS管理員的協助。

+0

我必須cpanm沒有接入(剛剛學會),當我嘗試在本地安裝,我得到的lib/perl5的/ 5.8.8/CPAN/Config.pm不可寫,錯誤 – kamal

+0

@kamal你可以用'wget -O - http://cpanmin.us |'在本地安裝'cpanm' perl - --self-upgrade -l' – Smylers