Renamed W3DHub.captured_command to simply W3DHub.command, replace usages of system with W3DHub.command, resolves command prompt's popping up on Windows under rubyw.

This commit is contained in:
2022-10-30 22:02:20 -05:00
parent 388c3a2606
commit ab73b62c4b
3 changed files with 18 additions and 15 deletions

View File

@@ -40,7 +40,7 @@ class W3DHub
end
end
def self.captured_commmand(command, &block)
def self.command(command, &block)
if windows?
stdout_read, stdout_write = IO.pipe
@@ -60,23 +60,26 @@ class W3DHub
status = -1
until (status = Process.get_exitcode(pid))
readable, _writable, _errorable = IO.select([stdout_read], [], [], 1)
if block
readable, _writable, _errorable = IO.select([stdout_read], [], [], 1)
readable&.each do |io|
line = io.readpartial(1024)
readable&.each do |io|
line = io.readpartial(1024)
block&.call(line)
block&.call(line)
end
else
sleep 0.1
end
end
stdout_read.close
stdout_write.close
status.zero?
else
IO.popen(command) do |io|
io.each_line do |line|
block&.call(line)
if block
io.each_line do |line|
block&.call(line)
end
end
end