lib/dolzenko/shell_out.rb in dolzenko-0.0.15 vs lib/dolzenko/shell_out.rb in dolzenko-0.0.16

- old
+ new

@@ -143,12 +143,14 @@ system "stty -echo raw lnext ^_" in_stream = ShellOut.getopt(:in, STDIN, *args) out_stream = ShellOut.getopt(:out, STDOUT, *args) writer = nil + spawned_pid = nil ShellOut.with_env(*args) do PTY.spawn(ShellOut.command(*args)) do |r_pty, w_pty, pid| + spawned_pid = pid reader = Thread.current writer = Thread.new do while true break if (ch = in_stream.getc).nil? ch = ch.chr @@ -185,10 +187,17 @@ end end rescue PTY::ChildExited => e return ShellOut::after(e.status.exitstatus, out_stream, *args) ensure - writer && writer.kill + if writer + writer.kill rescue nil + end + + if spawned_pid + Process.kill(-9, spawned_pid) rescue nil + end + system "stty #{ old_state }" end end def shell_out_with_system(*args) \ No newline at end of file