I need to run an external program and write to its STDIN, and read from its
STDOUT. I'm trying to do this using open(). Writing to its STDIN works fine
with the method below, but I cannot read from its STDOUT.
To simplify my tests, I wrote a simple C program called 'stdo' that
constantly generates data on its STDOUT:
#include <stdio.h>
#include <unistd.h>
int main(int argc, char** argv) {
while (1) {
printf("Hello\n");
fflush(stdout);
sleep(1);
}
return 0;
}
In Julia (0.4.1, Linux) I run this program like this:
julia> si=STDIN;
julia> (r,w)=redirect_stdin();
julia> (s,p)=open(`./stdo`,"w",w)
(Pipe(open => closed, 0 bytes waiting),Process(`./stdo`, ProcessRunning))
julia> r
Base.PipeEndpoint(open, 0 bytes waiting)
My understanding is that the C program's output is redirected to pipe 'w',
and it can be read from pipe 'r'. However, the pipe 'r' is always empty.
Obviously I'm doing something wrong, but I can't figure out what it is. Any
pointers appreciated.
-- mb