-
-
Save shugo/814403196d84b6c88080f3a39ed29b56 to your computer and use it in GitHub Desktop.
Unable to find any JVMs matching version "11"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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