# Document process interaction with stdin, stout, stderr

**URL:** <https://discourse.julialang.org/t/document-process-interaction-with-stdin-stout-stderr/7251>\
**Category:** Internals & Design\
**Tags:** proposal\
**Created:** [November 22, 2017, 5:12pm UTC](https://discourse.julialang.org/t/document-process-interaction-with-stdin-stout-stderr/7251 "2017-11-22T17:12:24Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [November 22, 2017, 5:12pm UTC](https://discourse.julialang.org/t/document-process-interaction-with-stdin-stout-stderr/7251/1 "2017-11-22T17:12:24Z")

</div>

Now that the 1.0 feature freeze is on the horizon, I’d like to re-surface a long-standing issue and make a plea for it to be addressed in 1.0.

Sometimes one wants to launch a long-living external program from Julia, and iteract with it via STDIN, STDOUT and STDERR. Note that direct access to the pipes is needed; it’s not enough to connect the pipes to files.

There is still no documented way to do this, although it is possible using undocumented functions, as I do [here](https://github.com/mbaz/Gaston.jl/blob/230fb48777c4805e1ead793793107d8f98863982/src/gaston_aux.jl#L431).

I initially raised this issue [back in 2015](https://github.com/JuliaLang/julia/issues/11824); it has also been discussed [here](https://github.com/JuliaLang/julia/issues/14437).

From the standpoint of a Julia programmer, having this functionality added to standard commands such as `readandwrite` would be ideal. A close second best would be to officially document and sanction a way to do this. My concern with relying on undocumented features is that code such as my `popen3` function may be broken any time Julia’s internal API changes.

If there is consensus that this is something that should be addressed, I’ll open a new issue.

– mb

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [November 23, 2017, 2:10am UTC](https://discourse.julialang.org/t/document-process-interaction-with-stdin-stout-stderr/7251/2 "2017-11-23T02:10:14Z")

</div>

I’m not really sure what you’re saying here. The supported way to get all three streams as pipes is the following

```julia
julia> stdin, stdout, stderr = (Pipe() for _ in 1:3);

julia> spawn(`cat`, stdin, stdout, stderr) # or equivalently spawn(pipeline(`cat`, stdin=stdin, stdout=stdout, stderr=stderr))
Process(`cat`, ProcessRunning)

```

The `readandwrite` function is mostly a convenience API for the common case of needing only stdin/stderr.  
Though, since we made processes readable/writable, we should probably change it to just return a process object.

Are you looking for better documentation?

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [November 23, 2017, 2:59am UTC](https://discourse.julialang.org/t/document-process-interaction-with-stdin-stout-stderr/7251/3 "2017-11-23T02:59:21Z")

</div>

Looking at this again, `readandwrite` was meant to be deprecated, there’s even a TODO left in the code to do so. PR incoming. Also, upon further consideration, the easiest way to do this (though less symmetric with the other streams) is:

```julia
open(pipeline(`cat`; stderr=Pipe()), "r+")
# Use p.{in,out,err} to access

```

This did have me looking back at some of this code and I found a bug. Issue filed: [https://github.com/JuliaLang/julia/issues/24717](https://github.com/JuliaLang/julia/issues/24717)

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [November 23, 2017, 3:43am UTC](https://discourse.julialang.org/t/document-process-interaction-with-stdin-stout-stderr/7251/4 "2017-11-23T03:43:57Z")

</div>

> [@Keno](#):
>
> Are you looking for better documentation?

Yes. Neither `Pipe()` nor that use of `spawn` are documented.

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [November 23, 2017, 3:56am UTC](https://discourse.julialang.org/t/document-process-interaction-with-stdin-stout-stderr/7251/5 "2017-11-23T03:56:38Z")

</div>

Ok, please feel free to file a doc issue. Maybe we should have a tag or milestone for doc issues that are addressable within the 1.0 timeframe. Would be good to take some time for docing after the feature freeze.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [November 23, 2017, 12:35pm UTC](https://discourse.julialang.org/t/document-process-interaction-with-stdin-stout-stderr/7251/6 "2017-11-23T12:35:34Z")

</div>

Yes, please!

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [November 27, 2017, 8:15pm UTC](https://discourse.julialang.org/t/document-process-interaction-with-stdin-stout-stderr/7251/7 "2017-11-27T20:15:57Z")

</div>

Done: [Improve documentation for process interaction using pipes · Issue #24810 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/24810)

I hope this issue can be added to the 1.0 milestone list.

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [November 27, 2017, 8:18pm UTC](https://discourse.julialang.org/t/document-process-interaction-with-stdin-stout-stderr/7251/8 "2017-11-27T20:18:57Z")

</div>

> [@Keno](#):
>
> open(pipeline(`cat`; stderr=Pipe()), “r+”)

@Keno Is this supposed to work in 0.6? It doesn’t work for me.

```
julia> p=open(pipeline(`gnuplot`; stderr=Pipe()), "r") # Note the "r"
(Pipe(RawFD(-1) closed => RawFD(20) open, 0 bytes waiting), Process(`gnuplot`, ProcessExited(0)))

```

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [November 27, 2017, 10:37pm UTC](https://discourse.julialang.org/t/document-process-interaction-with-stdin-stout-stderr/7251/9 "2017-11-27T22:37:14Z")

</div>

> [@mbaz](#):
>
> @Keno Is this supposed to work in 0.6? It doesn’t work for me.

No, I believe that change happened in the 0.7 timeframe.

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [November 28, 2017, 1:41am UTC](https://discourse.julialang.org/t/document-process-interaction-with-stdin-stout-stderr/7251/10 "2017-11-28T01:41:12Z")

</div>

OK, thanks! I’ll try it out when I have a chance to build 0.7.
