# Running an external program with sequential inputs

**URL:** <https://discourse.julialang.org/t/running-an-external-program-with-sequential-inputs/2771>\
**Category:** New to Julia\
**Created:** [March 20, 2017, 8:33am UTC](https://discourse.julialang.org/t/running-an-external-program-with-sequential-inputs/2771 "2017-03-20T08:33:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![michK](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@michK](https://discourse.julialang.org/u/michK)\
**Post date:** [March 20, 2017, 8:33am UTC](https://discourse.julialang.org/t/running-an-external-program-with-sequential-inputs/2771/1 "2017-03-20T08:33:30Z")

</div>

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](http://docs.julialang.org/en/stable/manual/running-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:

```
open(`program`)

```

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

[This](http://blog.leahhanson.us/post/julia/julia-commands.html) blog post is quite informative, and I believe something like:

```
(si,pr) = writesto('program')
write(si,input_1)
...
write(si, input_2)

```

might have worked on an older version of Julia, but the `writeto` function has been deprecated, as discussed [here](https://github.com/JuliaLang/julia/pull/6945).

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.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [March 20, 2017, 4:47pm UTC](https://discourse.julialang.org/t/running-an-external-program-with-sequential-inputs/2771/2 "2017-03-20T16:47:02Z")

</div>

Crossposted from [this StackOverflow question](http://stackoverflow.com/questions/42894447/running-an-external-program-with-sequential-inputs-from-julia-0-5-1), 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.

---

<div class="post-metadata">

**Author:** ![michK](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@michK](https://discourse.julialang.org/u/michK)\
**Post date:** [March 20, 2017, 5:19pm UTC](https://discourse.julialang.org/t/running-an-external-program-with-sequential-inputs/2771/3 "2017-03-20T17:19:50Z")

</div>

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.
