Skip to content

Instantly share code, notes, and snippets.

@shugo
Created December 16, 2021 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shugo/814403196d84b6c88080f3a39ed29b56 to your computer and use it in GitHub Desktop.
Save shugo/814403196d84b6c88080f3a39ed29b56 to your computer and use it in GitHub Desktop.
Unable to find any JVMs matching version "11"
require "open3"
cmd = "echo foo"
CONFIG = { shell_file_name: "/bin/zsh", shell_command_switch: "-c" }
signals = [:INT, :TERM, :KILL]
begin
opts = /mswin|mingw/ =~ RUBY_PLATFORM ? {} : {pgroup: true}
if CONFIG[:shell_file_name]
cmd = [CONFIG[:shell_file_name], CONFIG[:shell_command_switch], cmd]
end
Open3.popen3(*cmd, opts) do |input, output, error, wait_thread|
input.close
catch(:finish) do
loop do
rs, = IO.select([output, error], nil, nil, 0.5)
rs&.each do |r|
begin
s = r.read_nonblock(1024).force_encoding("utf-8").
scrub("\u{3013}").gsub(/\r\n/, "\n")
p s
rescue EOFError
p :EOF
exit
rescue Errno::EAGAIN, Errno::EWOULDBLOCK
next
end
end
end
end
status = wait_thread.value
pid = status.pid
if status.exited?
code = status.exitstatus
puts("Process #{pid} exited with status code #{code}")
elsif status.signaled?
signame = Signal.signame(status.termsig)
puts("Process #{pid} was killed by #{signame}")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment