Skip to content

Commit

Permalink
Update example code for outputting to a pipe
Browse files Browse the repository at this point in the history
As discussed in issue #119, the example code was not written correctly
and would fail on JRuby due to a race condition that didn't tend to
happen on MRI.

Fixes #119.
  • Loading branch information
sds committed Jul 11, 2019
1 parent 3912527 commit 9d60c0f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,18 @@ r, w = IO.pipe
proc = ChildProcess.build("echo", "foo")
proc.io.stdout = proc.io.stderr = w
proc.start
w.close

begin
loop { print r.readpartial(8192) }
rescue EOFError
end
Thread.new {
begin
loop do
print r.readpartial(8192)
end
rescue EOFError
end
}

proc.wait
w.close
```

Note that if you just want to get the output of a command, the backtick method on Kernel may be a better fit.
Expand Down

0 comments on commit 9d60c0f

Please sign in to comment.