Hello,

Gaston.jl is a plotting package based on gnuplot. Gnuplot is command-line
tool, so I send commands to it via a pipe. I open the pipe (on Linux) with
a ccall to "popen", and write gnuplot commands to the pipe using a ccall to
fputs.

This works fine, but I'm trying to see if Julia's native pipe and stream
functionality can make this process more Julian and, in the process, more
cross-platform. The documentation is encouraging:

"You can use [a Cmd] object to connect the command to others via pipes, run
it, and read or write to it." and "Julia provides a rich interface to deal
with streaming I/O objects such as terminals, pipes and TCP sockets."
Unfortunately, I just can't figure out how to use Julia's functionality for
this purpose. This is what I've tried (I am on Julia 0.3.9):

First, I tried using `open` with read and write:

    julia> f=open(`gnuplot`,"r+")
    ERROR: ArgumentError("mode must be \"r\" or \"w\", not \"r+\"")

So I tried with write only:

    julia> f=open(`gnuplot`,"w")
    (Pipe(open, 0 bytes waiting),Process(`gnuplot`, ProcessRunning))

So far, this looks good. I can see a gnuplot process running.

Then I try to `write` to the pipe:

    julia> write(f,"plot sin(x)")
    ERROR: `write` has no method matching write(::(Pipe,Process),
::ASCIIString)

OK, so let's try with `println`:

    julia> println(f,"plot sin(x)")
    (Pipe(open, 0 bytes waiting),Process(`gnuplot`, ProcessRunning))plot
sin(x)

and no plot is produced.

I can't figure out how to read from the pipe, either:

    julia> readbytes(f)
    ERROR: `readbytes` has no method matching readbytes(::(Pipe,Process))

    julia> readall(f)
    ERROR: `readall` has no method matching readall(::(Pipe,Process))

I'd appreciate any pointers. Thanks!

-- mb

Reply via email to