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

Can someone please outline to me how I can perform a system call like the following?
system q[ start /b /wait /low perl C:/Perl_activate/Run_this.pl] or pr +int STDERR "couldn't exec the perl program: $!";
and in addition pass a variable to the program Run_this.pl. This variable needs to be a two or three letter string. The program Run_this.pl needs to be able to pick up this variable and use it. I’m assuming that I need to use an @ARGV in the Run_this.pl program.

Replies are listed 'Best First'.
Re: command-line arguments and @ARGV
by davorg (Chancellor) on Jan 30, 2007 at 11:33 UTC

    What happens if you try:

    system qq[ start /b /wait /low perl C:/Perl_activate/Run_this.pl $var +] and print STDERR "couldn't exec the perl program: $!";

    You can probably[1] avoid an unnecessary shell process by using:

    my @cmd = qw[ start /b /wait /low perl C:/Perl_activate/Run_this.pl ]; system @cmd, $var;

    See perldoc system for more details.

    [1] I say "probably" because I have no idea whether this trick works on Windows.

    Update: Changed logical operator. Thanks to shmem for spotting it.

      Hmm...

      system qq[ start /b /wait /low perl C:/Perl_activate/Run_this.pl $var +] or print STDERR "couldn't exec the perl program: $!";

      Is system on Windows so much different that it returns a non-zero value on success (i.e. do Windows commands successfully exit with a non-zero status)?

      Otherwise, that should be

      system qq[ start /b /wait /low perl C:/Perl_activate/Run_this.pl $var +] and print STDERR "couldn't exec the perl program: $!";

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: command-line arguments and @ARGV
by glasswalk3r (Friar) on Jan 30, 2007 at 11:40 UTC

    I believe that Win32::Process will do it for you with less effort, including setting the process priority.

    Alceu Rodrigues de Freitas Junior
    ---------------------------------
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill