`open(cmd, "w")` gives back a tuple. Try using f, p = open(`gnuplot`,"w") write(f, "plot sin(x)")
There was a bit of discussion when this change was made (I couldn't find it with a quick search), about this returning a tuple--it's a little unintuitive, and could be `fixed` in a few different ways (easiest: returning a complex type that can be written to and read from), but it's probably been off most people's radar. If you're up for it, why don't you open an issue (if one doesn't exist). Anyway, for your particular application, you probably want `readandwrite`: help?> readandwrite search: readandwrite Base.readandwrite(command) Starts running a command asynchronously, and returns a tuple (stdout,stdin,process) of the output stream and input stream of the process, and the process object itself. Which *also* returns a tuple (but at least now you know). See also http://blog.leahhanson.us/running-shell-commands-from-julia.html, which has a full rundown of reading and writing from processes. Cheers! Kevin On Wed, Jun 17, 2015 at 9:03 AM, Miguel Bazdresch <[email protected]> wrote: > 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 > >
