sshkit: Fix handling of output streams, including in cases of error.

In SSHKit we do some weird stuff with stream handling depending on the packets (sic) we receive back from Net::SSH.

I’d like to write a test case script that produces buffered, and unbuffered output, line- and character-wise, on standard error, and standard out to test the correct usage.

With a pathologically badly behaved script, we could find a way to make this work reliably, I am sure.

About this issue

  • Original URL
  • State: open
  • Created 10 years ago
  • Comments: 25 (14 by maintainers)

Most upvoted comments

@daniel-gomes-sociomantic I may have misunderstood the problem here, but there is an option which can be applied to commands to stop non zero commands from raising an exception: raise_on_non_zero_exit: false. The command output is collected in the full_stderr and full_stdout attrs of the command object.

On SSHKit master, you could patch something like this on to the abstract back end (based on a mixture of the test and capture methods:

module SSHKit
  module Backend
    class Abstract
      def capture_error(*args)
        options = args.extract_options!.merge(raise_on_non_zero_exit: false, verbosity: Logger::DEBUG)
        executed_command = create_command_and_execute(args, options)
        # Do something with executed_command.full_stdout or executed_command.full_stderr
      end
    end
  end
end

Does this help?