Skip to content
Snippets Groups Projects
Unverified Commit 246db8a1 authored by Claudia's avatar Claudia
Browse files

Capture stdout during `popen_write`

Fix tests and fulfill intended semantics by having `popen_write`
transparently capture standard output.
parent 772032f1
No related branches found
No related tags found
No related merge requests found
......@@ -12,8 +12,25 @@ module Utils
raise ErrorDuringExecution.new(args, status: $CHILD_STATUS, output: [[:stdout, output]])
end
def self.popen_write(*args, **options, &block)
popen(args, "wb", options, &block)
def self.popen_write(*args, **options)
popen(args, "w+b", options) do |pipe|
output = ""
# Before we yield to the block, capture as much output as we can
loop do
output += pipe.read_nonblock(4096)
rescue IO::WaitReadable, EOFError
break
end
yield pipe
pipe.close_write
IO.select([pipe])
# Capture the rest of the output
output += pipe.read
output.freeze
end
end
def self.safe_popen_write(*args, **options, &block)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment