In my Julia code, I want to call various external commands that get data from standard input and produce output on standard output. I'd like to store data in strings and have them read and written to these processes. For definiteness, let's say the process is tr [a-z] [A-Z]. My wrapper would be

function toupper(string)
    fn, fh = mktemp()
    print(fh, string)
    close(fh)
    result = pipeline(fn, `tr [a-z] [A-Z]`) |> readstring
    rm(fn)
    result
end

(this is Julia 0.6 syntax; replace readstring by io->read(io,String))

I would like a cleaner way of doing this; ideally, a command printer(string) that creates a stream producing the contents of the string, such that the command above would be coded as

toupper(string) = pipeline(printer(string), `tr [a-z] [A-Z]`) |> readstring

(Indeed, there will be lots of commands like the above, and I'd like, for efficiency reasons, to avoid creating and deleting all these temporary files)

1 Answers

0
grok On

OK, I found it: printer(string) could just be coded as IOBuffer(string).