# Piping into an external program from Julia output

**URL:** <https://discourse.julialang.org/t/piping-into-an-external-program-from-julia-output/42691>\
**Category:** New to Julia\
**Tags:** pipes\
**Created:** [July 7, 2020, 10:03pm UTC](https://discourse.julialang.org/t/piping-into-an-external-program-from-julia-output/42691 "2020-07-07T22:03:47Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [July 17, 2020, 7:03am UTC](https://discourse.julialang.org/t/piping-into-an-external-program-from-julia-output/42691/13 "2020-07-17T07:03:14Z")

</div>

The problem is `run`, it should not be used here: `run` will send the output to stdout, or to `/dev/null` if `wait=true` (unless you play with undocumented arguments). You should give the result of `pipeline` directly to `myReverse`.

A pipeline is a `Cmd`. As the documentation says,

> You can use [the `Cmd`] object to connect the command to others via pipes, [`run`](https://docs.julialang.org/en/v1/base/base/#Base.run) it, and [`read`](https://docs.julialang.org/en/v1/base/io-network/#Base.read) or [`write`](https://docs.julialang.org/en/v1/base/io-network/#Base.write) to it.

So the `read` in `myReverse` can work directly on the `Cmd` object.

The pipeline execution will start when the `Cmd` is opened, and the output can then be read from the `Cmd` as if it was a file. This is what `read` does: Doing `@less read(`ls`, String)` shows that it redirects to the following method:

```julia
function read(cmd::AbstractCmd)
    procs = open(cmd, "r", devnull)
    bytes = read(procs.out)
    success(procs) || pipeline_error(procs)
    return bytes
end

```

Contrary to `run`, the `open` call returns a process from which one can read the pipeline output, see `@less open(`ls`)`. That’s why I use `open` rather than `run` in some of the examples above. But in simple cases you should just read directly from the `Cmd`.

---

_[View the full topic](https://discourse.julialang.org/t/piping-into-an-external-program-from-julia-output/42691)._
