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

This is rather embarassing, but I am baffled.

I'm writing a rather simple script to query a database, retrieve a couple of facts, and then iteratively launch another script using those facts as command line parameters.

NB This is all in a Win2000 environment. ActivePerl 5.8.

No biggie, right?

I can launch ordinary exe files (notepad.exe, calc.exe etc), however, try as I might I cannot launch a perl script.

I have tried the following command lines
script.pl arg1, ... argn Drive:\path\script.pl arg1, ... argn Drive:\path\perl.exe Drive:\path\script.pl arg1, ... argn
I've used them as both strings and arrays
i.e.
$cmd = "script.pl arg1, ... argn";
and
@cmd = ("script.pl", arg1, etc, argn);
Ive submitted them as
system( $cmd ); system( @cmd ); use Win32::Process; Win32::Process::Create($process, "C:\\Perl\\bin\perl.exe", here I put any/all command lines above, 0, CREATE_NEW_CONSOLE, ".") || die "Create: $!";
and also
Win32::Process::Create($process, "Drive:\path\script.pl", "arg1, ... argn", 0, CREATE_NEW_CONSOLE, ".") || die "Create: $!";
The system command returns:
'0' is not recognized as an internal or external command
(as do backticks)
The Process::Create returns a variety of:
Create: No such file or directory at scriptname.pl line nn.
I am frankly baffled. There must be something obvious that I'm missing, but I'm running out of guesses.

Does anybody have a clue?

Janitored by Arunbear - added code tags, as per Monastery guidelines

Replies are listed 'Best First'.
Re: launching perl processes from a perl script on Win2K
by inman (Curate) on Oct 14, 2004 at 10:04 UTC
    If you want to start a whole bunch of programs and you are not bothered about their return values then you need to start each command in a 'new window'. In UNIX you would add an ampersand to the comand. The windows approach would be to use the start command.

    The following example shows this in action. The main script starts a number of other scripts which run simultaneously. The command also uses wperl.exe which is perl without a command window.

    #! /usr/bin/perl -w use strict; use warnings; foreach (1..5) { system (qq(start wperl.exe -e "sleep($_);print 'Done!'")); } print "Launching application has finished\n";
      I do something like this to fork off another process on Win32.
      use Win32::Process; $bInherit = 0; $Dir = "c:\\"; $Flag = CREATE_SUSPENDED | CREATE_NEW_CONSOLE | HIGH_PRIORITY_CLASS ; if (Win32::Process::Create( $Process, $App, $Cmd, $bInherit, $Flag, $Dir ) ) { $Pid = $Process->GetProcessID(); print "\n\tnew process created with PID $Pid"; while (1 < $Process->Resume() ) { } $Result = $Process->Wait($Timeout * 1000); if (! $Result) { print "$tmp did not end in $Timeout sec, killed"; $Process->Kill(0); } else { # process ran ok, give message } } else { print "\nunable to create the new process.\n"; $tmp = Win32::FormatMessage(Win32::GetLastError() ) ; print "\n $0 Error: $tmp\n"; }
Re: launching perl processes from a perl script on Win2K
by Brutha (Friar) on Oct 14, 2004 at 07:18 UTC
    Hello,

    I just tried on a W2k machine with ActiveState 5.6.1 the following, which worked for me:

    #!perl.exe use strict; my $cmd = "perl.exe loretta.pl"; my @output = qx/$cmd/; print @output;
    No idea, why it did not work for you.

    And it came to pass that in time the Great God Om spake unto Brutha, the Chosen One: "Psst!"
    (Terry Pratchett, Small Gods)

      Just tried my @output = qx/$cmd/;
      You've put me on track of the real problem.
      Something is choking on one of my command line arguments.
      The string bla=1|0|-1|-1 was driving something crazy and producing the error message:
      '0' is not recognized as an internal or external command
      At least I have a way of getting this under control now.
      Thanks a lot.

        You must quote parameters that have "&" or "|" inside them:

        perl .... "bla=1|0|-1|-1"
launching perl processes from a perl script on Win2K
by miseryandsuffering (Initiate) on Oct 14, 2004 at 07:19 UTC
    I wasn't logged in when I posted the question.
    I'm taking ownership here
    Sorry for any confusion