Hi. I’m trying to write to the stdin of an external program and read from it’s stdout multiple times while it’s still executing.
For example, consider this C code that indefinetly reads an integer input a
and outputs a+1
:
#include<stdio.h>
int main()
{
int a;
while(1)
{
scanf("%d", &a);
printf("%d\n", a + 1);
}
return 0;
}
Does Julia support communication with this type of program?
My current best guess is (exec
is the filename of the compiled C program):
julia> proc = open(`./exec`, write=true, read=true)
Process(`./exec`, ProcessRunning)
julia> println(proc, "12")
julia> readline(proc)
From there, readline
stalls. Execution resumes if I read from proc.out.buffer
instead, but the buffer is empty. Also, while I can get something if I close the process (or proc.out
), this prevents further communication.
This topic gave me the impression that this usecase may not be supported in Julia. Is that the case?
Thanks in advance!