http://www.perlmonks.org?node_id=995695

charithd has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I need to execute remote perl script(script_to_call.pl) from my another perl script also passing @ARGV to script_to_call.pl . I tried with below but it not parse @ARGV:
do { local @ARGV; @ARGV = ("$OldTime","$NewTime","$WLSP/CDSServer11.log"); eval { system("ssh -o stricthostkeychecking=no $WLS './script_to_call. +pl'"); }; };

Replies are listed 'Best First'.
Re: Run a remote Perl script from within a Perl script with @ARGV
by Athanasius (Archbishop) on Sep 26, 2012 at 04:56 UTC

    Try this (untested):

    my @args = ('ssh', '-o', 'stricthostkeychecking=no', $WLS, './script_to_call.pl', $OldTime, $NewTime, "$WLSP/CDSServer11.log"); system(@args);

    @ARGV contains what was passed in on the command line. It is not used for passing to another script. See system.

    Hope that helps,

    Athanasius <°(((><contra mundum

Re: Run a remote Perl script from within a Perl script with @ARGV
by salva (Canon) on Sep 26, 2012 at 08:24 UTC
    use Net::OpenSSH; $s = Net::OpenSSH->new($WLS, master_opts => [-o => 'StrictHostKeyCheck +ing=no']); $s->system('./script_to_call.pl', $OldTime, $NewTime, "$WLSP/CDSServer +11.log");