# How to read long output from external command?

**URL:** <https://discourse.julialang.org/t/how-to-read-long-output-from-external-command/47870>\
**Category:** General Usage\
**Created:** [October 6, 2020, 4:07pm UTC](https://discourse.julialang.org/t/how-to-read-long-output-from-external-command/47870 "2020-10-06T16:07:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [October 6, 2020, 4:07pm UTC](https://discourse.julialang.org/t/how-to-read-long-output-from-external-command/47870/1 "2020-10-06T16:07:05Z")

</div>

I’m trying to read all the output from an external program like this (MWE):

```julia
out = Pipe()
run(pipeline(`head -c10 /dev/urandom`, stdout=out), wait=true)
close(out.in)
read(out) |> length
# shows "10" as expected

```

This is a snippet I found here on discourse, and I actually need `pipeline` (not just `read(cmd)`) because in the real code `stderr` and `stdin` arguments are also used.

The code above works fine when the output is relatively short with length less or equal to 65536 bytes. When the command outputs more bytes (increase `-c10` in the MWE), the same code suddenly hangs forever without any CPU usage. This happens at the `run(...)` line.

I don’t see any mention of such limitations in the docs for `pipeline` and cannot find any docs for `Pipe()` at all.  
How to modify the code so that longer outputs are also read correctly?

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [December 14, 2020, 6:20pm UTC](https://discourse.julialang.org/t/how-to-read-long-output-from-external-command/47870/2 "2020-12-14T18:20:45Z")

</div>

Bump: this still hangs on current julia, no idea how to properly read command output here…

---

<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:** [December 14, 2020, 6:26pm UTC](https://discourse.julialang.org/t/how-to-read-long-output-from-external-command/47870/3 "2020-12-14T18:26:51Z")

</div>

This seems to work:

```julia
file = read(`cat file.txt`,String)

```

From the help of `read`:

```julia
julia> ? read
...
  ───────────────────────────────────────────────────────────────────────────────────────────────────────────────

  read(command::Cmd, String)

  Run command and return the resulting output as a String.

```

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [December 14, 2020, 7:23pm UTC](https://discourse.julialang.org/t/how-to-read-long-output-from-external-command/47870/4 "2020-12-14T19:23:57Z")

</div>

This works, but my question is specifically about `pipeline`:

> I actually need `pipeline` (not just `read(cmd)` ) because in the real code `stderr` and `stdin` arguments are also used.

---

<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:** [December 14, 2020, 7:44pm UTC](https://discourse.julialang.org/t/how-to-read-long-output-from-external-command/47870/5 "2020-12-14T19:44:38Z")

</div>

Sorry.
