class Shred::Commands::ShellCommand::CommandLine
Attributes
command_line[R]
out[R]
Public Class Methods
new(command_line: nil, out: nil)
click to toggle source
# File lib/shred/commands/base.rb, line 11 def initialize(command_line: nil, out: nil) @command_line = command_line @out = out end
Public Instance Methods
run()
click to toggle source
# File lib/shred/commands/base.rb, line 16 def run Bundler.with_clean_env do if out Open3.popen3(command_line) do |stdin, stdout, stderr, wait_thr| install_signal_handler(wait_thr.pid) while out_line = stdout.gets out.write(out_line) end while err_line = stderr.gets puts err_line end wait_thr.value end else pid = Process.spawn(command_line) install_signal_handler(pid) Process.wait(pid) $? end end end
to_s()
click to toggle source
# File lib/shred/commands/base.rb, line 41 def to_s command_line.to_s end
Private Instance Methods
install_signal_handler(pid)
click to toggle source
# File lib/shred/commands/base.rb, line 46 def install_signal_handler(pid) # make sure Ctrl-C gets passed on to the child process # http://stackoverflow.com/questions/14635318/having-a-io-popen-command-be-killed-when-the-caller-process-is-killed Signal.trap('INT') do # propagate the signal to the child Process.kill('INT', pid) # send the signal back to this process Signal.trap('INT', 'DEFAULT') Process.kill('INT', 0) end end