tags:

views:

97

answers:

1

Hi All,

I am trying to open multiple processes in a Perl script on Windows. Program structure would look some thing like this...

 my($chld1_out, $chld1_in);
   my($chld2_out, $chld2_in);
   my($chld3_out, $chld3_in);
   my @cmds1=();
   my @cmds2=();
   my @cmds3=();

    $pid1 = open2($chld1_out, $chld1_in, 'ex1.exe')or die $!;
    $pid2 = open2($chld2_out, $chld2_in, 'ex2.pl')or die $!;
    $pid3 = open2($chld3_out, $chld3_in, 'ex3.exe')or die $!;

   print $chld1_in $cmds1[0];
   print $chld2_in $cmds2[0];
   $op1=<$chld1_out>;
   $op2=<$chld2_out>;
   if ( $op1 == 'done' && $op1 != 'done')
   print $chld1_in $cmds1[0];
   elsif ( $op1 != 'done' && $op1 == 'done')
   print $chld2_in $cmds2[0];
   elsif ( $op1 == 'done' && $op1 == 'done')
   print $chld1_in $cmds1[1];
   print $chld2_in $cmds2[1];
   .....
   .....
   for loops and while loops..... to process with the data output... and do conditional programming. 
   close $pid1 or die $!;
    close $pid2 or die $!;
    close $pid3 or die $!;

If it does how can I execute the Perl script ( ex2.pl ) one way i know is system($^X,"ex2.pl","arg") ;

I would appreciate fro your help on this ASAP...

Thanks,

-Abishek

+3  A: 

Probably not, "opening" a process for reading is usually a fork and a pipe behind the scenes. And fork-execs don't work on Windows*.

For executing a Perl script, just do it.

do 'ex2.pl';

And if you want to pass args:

{   local @ARGV = qw<One Two Three>;
    do 'ex2.pl';
}

When ex2.pl wants to access @ARGV it will be ( 'One', 'Two', 'Three' ). Of course if you want to do any of the perl shorthand ARGV tricks, it's better to localize the GLOB.

{ local *ARGV = [ qw<One Two Three> ]; ... }

* - I've long thought that a suitable workaround should be possible using Windows process structures which have a readable stdout and stderr, as a well as a writable stdin.

Axeman
`fork/exec` works just fine on Strawberry Perl >= 5.8
socket puppet
I would be really helpful if you can point me the workaround solution.. interaction btw ex1.exe and ex3.exe would be really great.
Abishek
so you mean if i install strawberry perl the above mentioned program will work ??????
Abishek
Strawberry Perl has a trick to implement forks under windows. I'm not sure how it works, it may be threads, or some magical windows feature abuse. But it does work for the most part.
Kent Fredric
Kent: It's using ithreads and it is NOT specific to Strawberry Perl. It's part of the core and was (IIRC) originally put together by the nice folks at ActiveState.
tsee
FYI :- The above mentioned code works for me :)
Abishek