On Thu, May 22, 2008 6:11 am, Chaitanya Vutukuru wrote: > And also please let me know, if these is not the correct correct/proper > channel for support. This is the proper place for perl bug reports, but not general support of perl. For help with perl programming, try http://perlmonks.org. > Here is the brief explanation of the perl script and the problem > we are facing: > In the script we create pipe like: > pipe(FROMDBREAD,FROMDBWRITE); > > we dup STDOUT and STDERR, to FROMDBWRITE pipe descriptor like: > open(STDOUT,">&FROMDBWRITE") || die "$ME (child): can't redirect STDOUT\n"; > open(STDERR,">&STDOUT") || die "$ME (child): can't redirect STDERR\n"; > > Then we will wait for the pipe descriptor in the while loop: > while(<FROMDBREAD>) { > .. > .. > } > > We know that few messages are loggedin STDOUT and STDERR, but we see > that the script is hanging in the above while statement. > We are telling it as a hang because its not coming out of that > while(for false) or even not running the statements under that while > (for true), it is just waiting at "while(<FROMDBREAD>)", which is > leading to the whole script hanging. > We and customer facing this issue in one particular scenario > and in some machines. I believe you are not understanding how pipes work; you may want to unless you are in non-blocking mode, reading on a pipe will wait for something to be written if there are any open write filehandles on the pipe. See http://www.opengroup.org/onlinepubs/009695399/functions/read.html and/or try the following: #!/usr/bin/perl use strict; use warnings; my $ME = "me"; open OUT, ">&STDOUT" or die "couldn't dup\n"; pipe(FROMDBREAD,FROMDBWRITE); #we dup STDOUT and STDERR, to FROMDBWRITE pipe descriptor like: open(STDOUT,">&FROMDBWRITE") || die "$ME (child): can't redirect STDOUT\n"; open(STDERR,">&STDOUT") || die "$ME (child): can't redirect STDERR\n"; print OUT "warning foo\n"; warn "foo"; print OUT "warned foo\n"; $SIG{ALRM} = sub { close FROMDBWRITE; close STDOUT; close STDERR; print OUT "closed\n" }; alarm 5; #Then we will wait for the pipe descriptor in the while loop: while(<FROMDBREAD>) { print OUT "got :$_:\n"; } print OUT "done\n";Thread Previous | Thread Next