From bd46382563954133c8b76ca3d25c9c099a279be0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 4 Jan 2011 23:17:28 -0800 Subject: [PATCH] Allow standard error to be read from Process --- lib/net/ssh/shell/process.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/net/ssh/shell/process.rb b/lib/net/ssh/shell/process.rb index be89b97..9774324 100644 --- a/lib/net/ssh/shell/process.rb +++ b/lib/net/ssh/shell/process.rb @@ -14,6 +14,7 @@ def initialize(manager, command, callback) @callback = callback @properties = {} @on_output = Proc.new { |p, data| print(data) } + @on_error_output = Proc.new { |p, data| print(data) } @on_finish = nil @state = :new end @@ -36,6 +37,7 @@ def run manager.open do state = :running manager.channel.on_data(&method(:on_stdout)) + manager.channel.on_extended_data(&method(:on_stderr)) @master_onclose = manager.channel.on_close(&method(:on_close)) cmd = command.dup @@ -75,6 +77,10 @@ def on_output(&callback) @on_output = callback end + def on_error_output(&callback) + @on_error_output = callback + end + def on_finish(&callback) @on_finish = callback end @@ -96,6 +102,11 @@ def on_stdout(ch, data) end end + def on_stderr(ch, type, data) + return unless @on_error_output + @on_error_output.call(self, data) + end + def on_close(ch) manager.on_channel_close(ch) finished!(-1)