system_command: improve EOF handling
This commit is contained in:
parent
c7e183ef9f
commit
e30f2af987
@ -197,10 +197,10 @@ class SystemCommand
|
|||||||
|
|
||||||
sig { params(sources: T::Array[IO], _block: T.proc.params(type: Symbol, line: String).void).void }
|
sig { params(sources: T::Array[IO], _block: T.proc.params(type: Symbol, line: String).void).void }
|
||||||
def each_line_from(sources, &_block)
|
def each_line_from(sources, &_block)
|
||||||
loop do
|
sources_remaining = sources.dup
|
||||||
readable_sources, = IO.select(sources)
|
while sources_remaining.present?
|
||||||
|
readable_sources, = IO.select(sources_remaining)
|
||||||
readable_sources = T.must(readable_sources).reject(&:eof?)
|
readable_sources = T.must(readable_sources)
|
||||||
|
|
||||||
break if readable_sources.empty?
|
break if readable_sources.empty?
|
||||||
|
|
||||||
@ -208,12 +208,15 @@ class SystemCommand
|
|||||||
line = source.readline_nonblock || ""
|
line = source.readline_nonblock || ""
|
||||||
type = (source == sources[0]) ? :stdout : :stderr
|
type = (source == sources[0]) ? :stdout : :stderr
|
||||||
yield(type, line)
|
yield(type, line)
|
||||||
rescue IO::WaitReadable, EOFError
|
rescue EOFError
|
||||||
|
source.close_read
|
||||||
|
sources_remaining.delete(source)
|
||||||
|
rescue IO::WaitReadable
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
sources.each(&:close_read)
|
sources_remaining.each(&:close_read)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Result containing the output and exit status of a finished sub-process.
|
# Result containing the output and exit status of a finished sub-process.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user