# Collecting all output from shell commands

**URL:** <https://discourse.julialang.org/t/collecting-all-output-from-shell-commands/15592>\
**Category:** General Usage\
**Tags:** shell\
**Created:** [September 28, 2018, 7:35am UTC](https://discourse.julialang.org/t/collecting-all-output-from-shell-commands/15592 "2018-09-28T07:35:43Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [October 16, 2018, 7:53am UTC](https://discourse.julialang.org/t/collecting-all-output-from-shell-commands/15592/7 "2018-10-16T07:53:11Z")

</div>

It looks like this works.

```julia
function communicate(cmd::Cmd, input)
    inp = Pipe()
    out = Pipe()
    err = Pipe()

    process = run(pipeline(cmd, stdin=inp, stdout=out, stderr=err), wait=false)
    close(out.in)
    close(err.in)

    stdout = @async String(read(out))
    stderr = @async String(read(err))
    write(process, input)
    close(inp)
    wait(process)
    return (
        stdout = fetch(stdout),
        stderr = fetch(stderr),
        code = process.exitcode
    )
end

@show communicate(`cat`, "hello")
@show communicate(`sh -c "cat; echo errrr 1>&2; exit 3"`, "hello")

```

---

_[View the full topic](https://discourse.julialang.org/t/collecting-all-output-from-shell-commands/15592)._
