lib/evrone/common/spawn/ssh.rb in evrone-common-spawn-0.0.4 vs lib/evrone/common/spawn/ssh.rb in evrone-common-spawn-0.0.5

- old
+ new

@@ -43,10 +43,14 @@ compute_exit_code command, exit_code, timeout, read_timeout end private + def normalize_nl(str) + str.gsub(/\r\n?/, "\n") + end + def build_command(env, command, options) cmd = command unless env.empty? e = env.map{|k,v| "#{k}=#{v}" }.join(" ") cmd = "env #{e} #{cmd}" @@ -78,33 +82,31 @@ exit_code || -1 # nil exit_code means that the process is killed end end def spawn_channel(command, read_timeout, &block) - @connection.open_channel do |channel| - read_timeout.reset - #env.each do |k, v| - # channel.env k, v do |_, success| - # yield "FAILED: couldn't execute command (ssh.channel.env)\n" if block_given? - # end - #end + channel.request_pty do |_, pty_status| + raise StandardError, "could not obtain pty" unless pty_status - channel.exec command do |_, success| + read_timeout.reset - unless success - yield "FAILED: couldn't execute command (ssh.channel.exec)\n" if block_given? - end + channel.exec command do |_, success| - channel.on_data do |_, data| - yield data if block_given? - read_timeout.reset - end + unless success + yield "FAILED: couldn't execute command (ssh.channel.exec)\n" if block_given? + end - channel.on_extended_data do |_, _, data| - yield data if block_given? - read_timeout.reset + channel.on_data do |_, data| + yield normalize_nl(data) if block_given? + read_timeout.reset + end + + channel.on_extended_data do |_, _, data| + yield normalize_nl(data) if block_given? + read_timeout.reset + end end end end end