Net::SSH - request a pty seems to put stderr in stdout

N

Najati Imam

Hi all,

As context, we're simply trying to remotely (automatically) "su" to a
different user and issue commands as that user, while still being able
to differentiate between stderr and stdout on the subsequent commands.
If there's a common pattern for doing this, then answering my specific
question isn't all that important (to me). Thanks!

So, I'm trying to use Net::SSH to do some remote automation and when we
need to su to do something, thus requiring a pty, it seems that the
on_extended_data doesn't get called on stderr and that it, instead, gets
mashed into on_data:

Example:
- - - - -
require 'rubygems'
require 'net/ssh'

command = "cat slartibartfast"

Net::SSH.start(host, user, :password => password) do |ssh|
channel = ssh.open_channel do |ch|
channel.request_pty do |ch, success|
raise "no pty!" if !success
end

ch.exec command do |ch, success|
raise "could not execute command" unless success

password_sent = false
ch.on_data do |c, data|
puts "stdout: " + data
end

ch.on_extended_data do |c, type, data|
puts "stderr: " + data
end
end
end
channel.wait
end
- - - - -

Output:
- - - - -
stdout: cat: cannot open slartibartfast
stdout:
- - - - -

If I take the request for the pty out, everything behaves as expected.
Is this intentional behavior? I have yet to dig into the source, but
will tomorrow.

Thanks again!
Najati
 
R

ryanstout

Hi all,

As context, we're simply trying to remotely (automatically) "su" to a
different user and issue commands as that user, while still being able
to differentiate between stderr and stdout on the subsequent commands.
If there's a common pattern for doing this, then answering my specific
question isn't all that important (to me). Thanks!

So, I'm trying to use Net::SSH to do some remote automation and when we
need to su to do something, thus requiring a pty, it seems that the
on_extended_data doesn't get called on stderr and that it, instead, gets
mashed into on_data:

Example:
- - - - -
require 'rubygems'
require 'net/ssh'

command = "cat slartibartfast"

Net::SSH.start(host, user, :password => password) do |ssh|
channel = ssh.open_channel do |ch|
channel.request_pty do |ch, success|
raise "no pty!" if !success
end

ch.exec command do |ch, success|
raise "could not execute command" unless success

password_sent = false
ch.on_data do |c, data|
puts "stdout: " + data
end

ch.on_extended_data do |c, type, data|
puts "stderr: " + data
end
end
end
channel.wait
end
- - - - -

Output:
- - - - -
stdout: cat: cannot open slartibartfast
stdout:
- - - - -

If I take the request for the pty out, everything behaves as expected.
Is this intentional behavior? I have yet to dig into the source, but
will tomorrow.

Thanks again!
Najati

I know this is from years ago, but I'm having the same problem, did anyone happen to find a solution to this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top