At 05:14 PM 6/5/02 +0100, Alan John Drew wrote:
>I have a program which I want to have a bi-directional pipe to (i.e both 
>write and read). I am unable to tee it to a file and then read the file, 
>so reluctantly started to investigate the IPC modules. I have a snippet of 
>code here, which again works (sort of), just not in the way that I need...
>
>#!/usr/bin/perl -w
>
>use IPC::Open2;
>use IO::Handle;
>
>$program="maxent";
>($reader, $writer) = (IO::Handle->new, IO::Handle->new);
>open2($reader, $writer, $program);
>
>chomp($out = <$reader>);
>
>close $reader;
>close $writer;
>print STDOUT $out."\n";
>
>werd@psw283~/temp$ ./pipe.pl
>  Format USR is implimented (True/False) =  T
>werd@psw283~/temp$
>forrtl: severe (24): end-of-file during read, unit 5, file stdin
>cannot read in maxent
>
>
>As you can see, the line beginning with Format USR..... does indeed read
>correctly. However, there are many more lines where this one has come from
>and reading them all is the idea. Any clues?

Well, it depends on when your program is expecting input and how much 
output it generates.  You haven't tried to read any more lines from 
it.  You haven't tried to write any lines to it.  As the IPC::Open2 POD 
states, if the I/O exchange protocol is predictable and there's no 
buffering issues, you can handle this by performing the right number of 
reads and writes in the proper sequence.  If not, you'll need to use 
select() or something hairier.
--
Peter Scott
Pacific Systems Design Technologies        Boston Perl Classes in July:
http://www.perldebugged.com/               http://stemsystems.com/class/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to