How to read long output from external command?

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

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?

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

This seems to work:

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

From the help of read:

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

  read(command::Cmd, String)

  Run command and return the resulting output as a String.


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.

1 Like

Sorry.