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

Ok ... I'm tearing my hair out ...
I can't find the solution.
I'm trying to use the Lingua::Ispell module.
The first time I call spellcheck(), for some reason it dumps a Content-type header.
Inside spellcheck() it makes a call to _init() which calls IPC::open2() to open a communication channel with ispell.
The header is printed during this call.
(And ispell doesn't print headers anywhere ... i looked through the code)
I was thinking since Lingua::Ispell has bi-directional channel opened with ispell, the only output that will make it on to the screen/browser is that to STDERR.
I tried spawning ispell with 2>/dev/null, but then the spawn fails.

HEEEEEEEEELLLLLLP!
:-(

Replies are listed 'Best First'.
Re: Lingua::Ispell
by converter (Priest) on Apr 16, 2001 at 10:49 UTC

    This type of problem, while it may seem like dark magic when it's happening to you, is almost always the result of a piece of code doing exactly what it's supposed to do.

    If we had some code to look at (trimmed down to the smallest possible chunk of code that still demonstrates the problem), we might be able to steer you in the right direction, or ask some questions that might lead to a solution.

      print "Content-type: text/html\n\n";
      use Lingua::Ispell;
      my @words = Lingua::Ispell::spellcheck("word");


      That's enough to cause the header to appear.
      This only happens under httpd, running from console is fine.

      It turns out that the IPC module makes a copy of STDOUT or something similiar to that effect.
      Anything I printed to STDOUT before, gets printed again!!
      Might this somehow have to do with Apache buffering?
        What happens if you put a '$| = 1;' above the print? If this fixes it, you've run up against STDIO buffering, not Apache's.
Re: Lingua::Ispell
by Kryptolus (Initiate) on Apr 16, 2001 at 10:05 UTC
    The exact header is:
    Content-Type: text/html; charset=ISO-8859-1
Re: Lingua::Ispell
by Kryptolus (Initiate) on Apr 16, 2001 at 09:55 UTC
    Ok. I spent even more time on it ...
    The ispell binary has nothing to do with it.
    I get the header, even if i call a different program.

      Sounds like the call to fork() (to allow you to run the other program) is simply flushing an output buffer; something that newer Perls do before fork()ing in order to prevent the contents of the buffers being flushed by both the parent and child (which could produce doubled output).

              - tye (but my friends call me "Tye")