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


I have the following code which works perfectly on linux i get the ouput from the first open($pid1). And send it as the input to the second open($pid2).

local $pid1=open(README,"$DD bs=$BYTERATE if=$DISC|$GZIP|") or die "not forking1\n";

local $pid2=open(WRITEME,"|$NC $SERVER $PORT") or die "not forking2\n";

while (<README>){
    print WRITEME $_;
}


The question is, how can i make this piece of code work on win2000?? since fork is not very well supported. I know for sure forking pipe with open() just do not work. I ve read in perldoc about a workaround, but it does not cut it for me, since i really need to fork this proceses and get into the while (<README>) any ideas perlmonks??

Replies are listed 'Best First'.
Re: forking pipe open
by Abigail-II (Bishop) on Aug 13, 2002 at 09:00 UTC
    fork has been available from windows platforms since perl 5.6.0. I never touch Window systems, but as far as I know, pipe open is supported on Windows - with the exception of opening |- and -| (which kind of surprises me, as fork is now supported). See perlport.

    Abigail

Re: forking pipe open
by fokat (Deacon) on Aug 13, 2002 at 04:26 UTC
    Well, the fork() call is as well supported as dd and gzip :) (ie, not). If I read your example correctly, you seem to want to read a disk (in raw or character mode), gzip it and send it somewhere using something along the lines of netcat.

    My first suggestion would be to write a few more lines of code and implement the whole thing in perl, which would allow you to run your task anywhere, without the overhead of multiple processes. Take a look at IO::Zlib and IO::Socket, which would do all the work for you.

    Also note that in Win32, pipelines used to be very inefficient. The whole output of each member of the pipeline is executed up to completion and its output sent to a temporary file. Then the next member is fed with the temporary file and its output treated in a similar way, untill all the members have run. I would not be surprised if this were the case even today.

    Regards.

      Hey thanks good idea about using Zlib, i was already trying to replace netcat using the socket library anyways.

      The only program i just dont have a clue on how to get rid of would be ofcourse dd since i need to read a whole disc. any ideas man?
Re: forking pipe open
by Moonie (Friar) on Aug 12, 2002 at 23:05 UTC