in reply to need help with open2, please!

You need to close the TOENSCRIPT handle to tell the process that you've finished writing to it. Move close(TOENSCRIPT) above the line where you read the output, like so:
print TOENSCRIPT (@burstpage); close(TOENSCRIPT); my @burstpage_ps = <FROMENSCRIPT>; close(FROMENSCRIPT);

stephen


Update 1: Added code example.

Replies are listed 'Best First'.
Re: Re: need help with open2, please!
by gcomeaux (Novice) on May 02, 2001 at 22:08 UTC
    This sounds like a problem I'm having with both the Lingua::ISpell and Text::ISpell modules. Every script I write with them just hangs when an attempt is made to read from the spawned process's output pipe. Both modules use an open2 call from an _init() function prior to calling spellcheck(). Here's what they look like:
    sub _init { ... $Lingua::Ispell::pid = open2( *Reader, *Writer, $Lingua::Ispell::path, '-a', '-S', @options, ); ... } sub spellcheck { _init() or return(); # caller should really catch the exception fro +m a failed open2. my $line = shift; local $/ = "\n"; local $\ = ''; chomp $line; $line =~ s/\r//g; # kill the hate $line =~ /\n/ and croak "newlines not allowed in arguments to Lingua +::Ispell::spellcheck!"; print Writer "^$line\n"; my @commentary; local $_; while ( <Reader> ) { chomp; last unless $_ gt ''; push @commentary, $_; }
    From a debugger, I see that it hangs at the line:
    while ( <Reader> ) {
    By the by, I'm trying to write a litte script to check fields in a database for spelling errors and write out a log of misspelled words. Any ideas on what I'm doing wrong? ( I can't even run the example code for these modules without hanging. Oh, I'm on a Windows machine and cannot use a real operating system.)
      It sounds like you are Suffering from Buffering. Though not exactly. Anyways you are expecting output while it is expecting input, and nobody is going to be happy.

      What happens if you try to close Writer before reading? Once it finds out that there will be no more input, you should get your output and be happy...

        call select on those file handles to prevent the reader/writer dead-locking. (Or just fork into seperate reader/writer process if that's feasible).
        I edited the module code to close Writer before reading, but no luck. I'm afraid I may be dealing with limitations of the ispell compiled for Windows NT - but this is just a guess from reading some of the docs on open2... Thanks though.
Re: Re: need help with open2, please!
by blueflashlight (Pilgrim) on May 02, 2001 at 19:08 UTC
    thank you!!! that solved all my problems; life is good. -s-