Hello,

I'd be grateful if you could take a look at some code and suggest
improvements.

I'm trying to interact with a long-lived process (gnuplot). This process
reads commands from its STDIN; after each command is executed, it produces
output on either its STDOUT or STDERR. It's impossible to predict ahead of
time which of the two streams will be used.

To simplify my tests, I wrote an "echo server" in C, which reads a
character from its STDIN and outputs it again over either STDOUT or STDERR.
The code is here: https://gist.github.com/mbaz/1e242694a9c4f1eca576

Then I wrote a julia program that reads a character from its own STDIN,
sends it to the C echo server, and then tries to read the server's STDOUT
and STDERR until it finds a character. The code is here:
https://gist.github.com/mbaz/bb7e2cbaaecc031b1d88

This code works, but I don't know if it is the best approach. Two specific
questions I have:

* Is my `popen3()` function necessary? This closed issue seems to suggest
it's not, but I can't figure out how to accomplish what I need in a more
simple manner: https://github.com/JuliaLang/julia/issues/11824

* Are global variables required to share data with asynchronous tasks?
Since global variables are slow, this approach may produce undesired code
slowdowns.

Thanks,

-- mb

Reply via email to