views:

70

answers:

3

Hello,

I am relearning Perl after about 10 years of non use.

I did a copy and paste of the two scripts below from one of the answers for a similar question on this site. I have checked and double checked the 'path' and tried several deviations, but I still get the same answer -'The system cannot find the path specified'. Any help would be greatly appreciated!

It does get to the "starting child process" and the exits with the error message 'The system cannot find the path specified.'

Below is the cut and past of the original two scripts

parent.pl:

#!/usr/bin/perl


use warnings;

use Win32;
use Win32::Process;

$| = 1;

my $p;

print "Starting child process ... \n";

Win32::Process::Create(
    $p,
    'c:\Perl\perl.exe',
    'perl hello.pl',
    1,
    NORMAL_PRIORITY_CLASS,
    '.',
) or die Win32::FormatMessage( Win32::GetLastError() );

print "Waiting three seconds before killing 'hello.pl'\n";

for (1 .. 3) {
    print;
    sleep 1;
}
$p->Kill(0)
    or die "Cannot kill '$p'";

hello.pl

#!/usr/bin/perl

$| = 1;

print "Hello World\n";
print "Sleeping 1000 seconds\n";

for (1 .. 1000) {
    sleep 1;
    print '.';
}
+2  A: 

You need to escape the backslashes in your path, or use forward slashes.

Look at this somewhat related post.

cdonner
Thank you, I appreciate your effort, but this did not work.I tried c:/Perl/perl.exec:\\Perl\\perl.exeand even c:\/Perl\/perl.exe just for fun :-}
jpk
It seems that you pasted Unix scripts. I don't use perl much, but this line I believe will not work in Windows: #!/usr/bin/perl Here are some Windows examples:http://forums.devshed.com/perl-programming-6/problem-with-win32-process-create-360040.html
cdonner
A: 

Thank you, but #!/usr/bin/perl is simply ignored in winperl...I was able to alter the script to whats listed below and it will start with "Starting child process..." and then it just hangs....any ideas anyone?

!/usr/bin/perl

use warnings; use Win32; use Win32::Process;

$| = 1;

my $p;

print "Starting child process ... \n";

Win32::Process::Create( $p, "c:\Perl\perl.exe", perl c:\\apache\\cgi-bin\\hello.pl, 1, NORMAL_PRIORITY_CLASS, '.', ) or die Win32::FormatMessage( Win32::GetLastError() );

print "Waiting three seconds before killing 'hello.pl'\n";

for (1 .. 3) { print; sleep 1; } $p->Kill(0) or die "Cannot kill '$p'";

jpk
+1  A: 

(This answer will be edited as conditions check out)

  1. check that there is a c:\Perl directory - it may be case-sensitive (eg. C:\ not c:\)
  2. make sure there's a perl.exe listed in that directory, the actual path might be C:\Perl\bin\perl.exe
  3. 'perl hello.pl' may need to be the full qualified perl path (eg 'C:\Perl\perl.exe hello.pl')


Side Note:

  1. Since you're using single-quotes (') you shouldn't need to escape your backslash (\)
  2. If processing on windows you may change: #!/usr/bin/perl to the specified windows path #!C:\Perl\perl.exe , however I don't think this really matters as much on windows, it just helps you know where the executable is for times like this.
vol7ron