Running an external program with sequential inputs


I want to run an external program, lets call it program, sequentially piping inputs to its standard input. Lets call the inputs input_1, input_2 etc.

I then want the standard output of the program to be piped back into memory, for example a Julia data structure, or if this is not possible, written to a text file.

I can run the external program with:

run(`program input_1 input_2`)

which results in the standard output of the program being displayed to the shell.

I however need to feed the inputs sequentially, so cannot use this approach.

I have looked on the External Programs documentation page and I believe I should use the open function, but I cannot figure out how to use it.

When I run:


the external program complains that it cannot run without an input.

This blog post is quite informative, and I believe something like:

(si,pr) = writesto('program')
write(si, input_2)

might have worked on an older version of Julia, but the writeto function has been deprecated, as discussed here.

Additionally, I want the program to run in the background. Currently it spawns a new terminal window. I think this might be a function of the external program so I am not sure if this can be specified in Julia.


Crossposted from this StackOverflow question, where it has since found an answer and some discussion. If you do cross-post like this, please state that you are doing so to prevent folks from duplicating efforts and splintering discussion across the different sites.


Appologies for that, I only thought to ask on this forum a bit later and forgot to reference the cross-post. Thanks for adding the link.