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

Hi monks!

I am running a script in Activestate Perl that uses a program running in the Cygwin enviroment. The program prints several lines of output.

my $pid = open2(*Reader, *Writer, 'primer3_core.exe' ); print Writer "$primer3input\n"; close Writer; my @result = <Reader>; print "@result";
Everyting seems to work fine, and the @result gets the first line of output from primer3, but then everything stops before it is printed. At least until I kill the primer3 process manually, then the script gets the rest of the output and continues. Just writing the input to a file and then doing
my $result = `cat tempfile | primer3_core.exe`;
works fine. I have no idea why it's not working with open2, especially because the author of primer3 uses open3 in one of his own perl scripts...

Replies are listed 'Best First'.
Re: Windows/Cygwin and open2
by ikegami (Patriarch) on Aug 13, 2004 at 17:24 UTC
    <FILE>, in a list context (as in your code) means read all lines in the file, until the EOF is reach. (As far as I know) EOF isn't reached as long as primer3_core.exe is running. Maybe you want $result = <Reader>?
Re: Windows/Cygwin and open2
by ysth (Canon) on Aug 15, 2004 at 15:27 UTC
    Some stabs in the dark:

    What is $ENV{CYGWIN} set to? If it contains "tty", try changing to "notty" (while no cygwin programs are running).
    Does primer3_core write to stderr? What is primer3 and where can we find it?

      $ENV{CYGWIN} is set to ntsec tty (for sshd), I will try to set it to notty, thanks. Primer3 is a bioinformatics tool to find PCR primers, it can be downloaded as source at http://frodo.wi.mit.edu/primer3/primer3_code.html
Re: Windows/Cygwin and open2
by crenz (Priest) on Oct 15, 2004 at 10:55 UTC
    FWIW, I use GNU Octave on MacOS X and Windows and talk to it using IPC::Open2. Perl seems to not be able to detect the EOF, so I add a "quit" to the commands I send to Octave. Then, it works.