2013-01-08 200 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