delano / rye

Safe, parallel access to Unix shells from Ruby
http://delano.github.com/rye
MIT License
234 stars 32 forks source link

cannot 'switch off' stderr output of remote ssh command execution #65

Open torstello opened 9 years ago

torstello commented 9 years ago

Hi Delano,

maybe you can direct me to a solution; i don't manage to suppress the printing to STDERR when a remote cmd fails (like date --foobar). (I'm collecting and further process the output of rye::set / rye::box commands)

I tried last with this rye_opts:

    RYE_OPTS   = { 
                  :error           => false,
                  :verbose      => Logger::FATAL,  # this was a try after reading Net::SSH.start docs
                  :safe            => false,
                  :quiet           => true,
                  :password_prompt => false }

but it always prints the cmd error to $stderr:

D, [#73533] DEBUG -- : host_exec(host='lxt', cmd='date -I --foo', params='', u='', dry='false'
D, [#73533] DEBUG -- : Tmt::RyeCmdExec.get_rye_box(lxt, {:error=>false, :verbose=>4, :safe=>false, :quiet=>true, :password_prompt=>false})
D, [#73533] DEBUG -- host_exec: rye_box.execute('date -I --foo', '')
>>>>>>
date: unrecognized option '--foo'
Try `date --help' for more information.
<<<<<<<
D, [#73533] DEBUG -- : calling format_output with => [, date: unrecognized option '--foo'; Try `date --help' for more information., 1, ]

The only way that really works is redirect the stderr of my cli program like this tmt host -h testserver date -- --foo 2>/dev/null

But of course that's not a solution.

Any hint is very much appreciated!

torstello commented 9 years ago

I also tried:

    io_trash = File.open(File::NULL, 'w')
    RYE_OPTS   = { 
                    :error           => io_trash,
    io_trash = File.open('/dev/null', 'w')
    RYE_OPTS   = { 
                    :error           => io_trash,
    io = StringIO.new('dontbotherme')
    RYE_OPTS   = { 
                  :error           => io,

with all this, the error still ends up on STDERR. The only thing that changed it was :error => STDOUT

torstello commented 9 years ago

i didn't want to close this issue :)