Hello joachim,
I had to deal with this issue for a program I spend some time
developing for (POPFile).
The "platform compatible" way to do this, as far as I was able to
determine is as follows (and according to the following constraints
and "features"):
Constraint 1) "select" only works on sockets in MSWin32 (ActivePerl)
Feature 1) "-s" returns the amount of data available in a pipe on
MSWin32 but on no other platforms (as far as I was able to determine).
Constraint 2) "-s" returns "0" data available on a pipe that has had
any IO performed on it since the pipe last had data sent.
Feature 2) "pipe()" will return a pair of handles, one of which is
writable, the other readable.
First, you create a pipe, then you fork. The child writes on the
writable end of the pipe, and the parent reads the readable end.
To tell if a pipe has any data in MSWin32, do a "-s $pipe". On other
platforms, do a non-blocking select. Do these operations frequently,
and do "select( undef, undef, undef, $time)" between them. If "-s
$pipe" returns a positive number, read that many bytes. If "select" on
non-MSWin32 returns the pipe handle, <> it.
Let me know if that works for you.
Also, I'm not sure which of the "special" open syntaxes you are using
work in MSWin32, so you may have to acheive the same thing using one
script and fork(). I'm not sure if -s will return the size of STDIN
either.
Friday, February 6, 2004, 1:49:32 AM, you wrote:
jgad> - snip ----------------
jgad> parent:
jgad> my $proc = open (RD,"perl child.PL $$|");
jgad> vec($AnfMask, fileno (RD), 1) = 1;
jgad> while 1 {
jgad> select ($ErgMask = $AnfMask , undef , undef , 15 );
jgad> if (vec($ErgMask,fileno (RD), 1)){
jgad> # The child lives and is active
jgad> @a=<RD>
jgad> # If it enough is kills the child and last
jgad> }else{
jgad> # child is not active --> if the child is present, kill it
jgad> # start the child again
jgad> }
jgad> }
jgad> child:#
jgad> while 1 {
jgad> # do anything
jgad> print STDOUT "blabla";
jgad> select (undef, undef, undef , 10) # wait 10 seconds
jgad> }
jgad> - end snip ----------------
--
Best regards,
Sam mailto:[EMAIL PROTECTED]
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs