Capture stdout during popen_write
Fix tests and fulfill intended semantics by having `popen_write` transparently capture standard output.
This commit is contained in:
parent
772032f18a
commit
246db8a134
@ -12,8 +12,25 @@ module Utils
|
|||||||
raise ErrorDuringExecution.new(args, status: $CHILD_STATUS, output: [[:stdout, output]])
|
raise ErrorDuringExecution.new(args, status: $CHILD_STATUS, output: [[:stdout, output]])
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.popen_write(*args, **options, &block)
|
def self.popen_write(*args, **options)
|
||||||
popen(args, "wb", options, &block)
|
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
|
end
|
||||||
|
|
||||||
def self.safe_popen_write(*args, **options, &block)
|
def self.safe_popen_write(*args, **options, &block)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user