# Piping input and output

**URL:** <https://discourse.julialang.org/t/piping-input-and-output/61157>\
**Category:** General Usage\
**Tags:** run\
**Created:** [May 14, 2021, 1:49pm UTC](https://discourse.julialang.org/t/piping-input-and-output/61157 "2021-05-14T13:49:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 14, 2021, 1:49pm UTC](https://discourse.julialang.org/t/piping-input-and-output/61157/1 "2021-05-14T13:49:14Z")

</div>

I would like to do something as simple as:

```julia
grep AA < box.inp > box.out

```

using `run`. Is the only way to do this one of the cumbersome options discussed [here](https://discourse.julialang.org/t/piping-into-an-external-program-from-julia-output/42691/13)?

(meaning using `pipeline` etc?) Or is there a simple alternative? I do not need even to store the output of the command in the section, just run it as an external command.

---

<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:** [May 14, 2021, 2:25pm UTC](https://discourse.julialang.org/t/piping-input-and-output/61157/2 "2021-05-14T14:25:35Z")

</div>

I think you should indeed use `pipeline` for that. As the documentation for `run` says:

> Use `pipeline` to control I/O redirection.

But it’s not that bad?

```julia
pipeline("box.inp", `grep AA`, "box.out") |> run

```

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 14, 2021, 3:09pm UTC](https://discourse.julialang.org/t/piping-input-and-output/61157/3 "2021-05-14T15:09:25Z")

</div>

That does not work for the command I am actually trying to run (instead of `grep`), probably because some difference related to how it outputs the data.

What is working is this:

```julia
  using Supressor
  output = @capture_out run(pipeline(`cat processed.top`,`plumed partial_tempering $(λ[i+1])`))      
  open("$out/topology.top","w") do io
    write(io, output)  
  end

```

Maybe someone who understands what this `capture` does might have any idea of what is going on.

Nobody invented a macro like:

```julia
@sh grep AA < box.inp > box.out

```

to just call a shell? Given that `;` gets one into a shell where that works, seems feasible, isn’t it?

---

<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:** [May 14, 2021, 5:07pm UTC](https://discourse.julialang.org/t/piping-input-and-output/61157/4 "2021-05-14T17:07:43Z")

</div>

Well you can do `run(`bash -c "grep AA < box.inp > box.out"`)` 🙂

But can you give more information on what fails with `run(pipeline("processed.top", `plumed partial_tempering $(λ[i+1])`, "$out/topology.top"))` ?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 14, 2021, 5:22pm UTC](https://discourse.julialang.org/t/piping-input-and-output/61157/5 "2021-05-14T17:22:48Z")

</div>

> [@sijo](#):
>
> But can you give more information on what fails with `run(pipeline("processed.top", `plumed partial\_tempering $(λ[i+1])`, "$out/topology.top"))` ?

Sure, apparently what was failing was my capacity to read a user guide. 😬
