# Run program with string input and output

**URL:** <https://discourse.julialang.org/t/run-program-with-string-input-and-output/134942>\
**Category:** General Usage\
**Created:** [January 7, 2026, 9:11pm UTC](https://discourse.julialang.org/t/run-program-with-string-input-and-output/134942 "2026-01-07T21:11:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [January 7, 2026, 9:11pm UTC](https://discourse.julialang.org/t/run-program-with-string-input-and-output/134942/1 "2026-01-07T21:11:57Z")

</div>

How do I run a program with a string on its stdin and get its output as a string?

This works but it’s a little verbose.

```julia-auto
julia> let s = "hello"
           io = IOBuffer()
           run(`cat`, IOBuffer(s), io)
           seekstart(io)
           read(io, String)
       end
"hello"

```

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [January 7, 2026, 9:25pm UTC](https://discourse.julialang.org/t/run-program-with-string-input-and-output/134942/2 "2026-01-07T21:25:25Z")

</div>

Maybe

```julia-auto
julia> read(pipeline(IOBuffer("hello"), `rev`), String)
"olleh"

```

---

<div class="post-metadata">

**Author:** ![tecosaur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tecosaur/32/23206_2.png) [@tecosaur](https://discourse.julialang.org/u/tecosaur)\
**Post date:** [January 8, 2026, 7:28am UTC](https://discourse.julialang.org/t/run-program-with-string-input-and-output/134942/3 "2026-01-08T07:28:47Z")

</div>

While I know this isn’t the “done thing” with Julia, it would be nice to be able to pun on `|` and shell pipelines and do `"hello" | `rev``.

---

<div class="post-metadata">

**Author:** ![HanD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hand/32/213908_2.png) [@HanD](https://discourse.julialang.org/u/HanD)\
**Post date:** [January 8, 2026, 8:45am UTC](https://discourse.julialang.org/t/run-program-with-string-input-and-output/134942/4 "2026-01-08T08:45:53Z")

</div>

You can easily do that for yourself:

```julia-auto
julia> Base.:|(s::AbstractString, cmd::Cmd) = read(pipeline(IOBuffer(s), cmd), String)
julia> "hello" | `rev`
"olleh"

```

That being said, it would probably be more Juliaesque to use the `|>` operator for this.

```julia-auto
julia> Base.:|>(s::AbstractString, cmd::Cmd) = read(pipeline(IOBuffer(s), cmd), String)
julia> "hello" |> `rev`
"olleh"

```
