# Open3 and ssh

**URL:** <https://www.ruby-forum.com/t/open3-and-ssh/147475>\
**Category:** Ruby\
**Created:** [September 2, 2008, 9:05am UTC](https://www.ruby-forum.com/t/open3-and-ssh/147475 "2008-09-02T09:05:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [September 2, 2008, 9:05am UTC](https://www.ruby-forum.com/t/open3-and-ssh/147475/1 "2008-09-02T09:05:47Z")

</div>

I’m writing an app using RubyCocoa on MacOS X 10.4.11 which i want to  
implement a Pseudo-terminal connected to a remote host via ssh.

When i test ssh from command line i get the waiting prompt and escape  
sequences, login and logout messages.  
But, testing with ruby, ssh no more sends the waiting prompt, nor escape  
sequences and even no logout message.  
I think this is because ssh “sees” my UI isn’t a peudo-terminal even if  
i make use of the option -T to force (?) allocation of it (before that i  
got the known message “Pseudo-terminal will not be allocated because  
stdin is not a terminal.”).  
And because i don’t see any control characters, i think ssh “knows” my  
UI isn’t a pseudo-terminal from the beginning of the connection.

I suppose i need to implement “something” but i lak info on what and how  
to do it. I suspect this is at a low level (tty?).

## here is my ruby code :

#! /usr/bin/env ruby

require ‘open3’

ENV[‘TERM’]=“ansi”  
ansi\_red="\e[31m"  
ansi\_clear="\e[0m"

Open3.popen3(“ssh -T TT”) { |stdin, stdout, stderr|  
Thread.start do  
while c=STDIN.getc  
stdin.print c.chr  
end  
end  
Thread.start do  
while line=stderr.gets  
puts ansi\_red+line.chomp+ansi\_clear  
end  
end  
while c=stdout.getc  
print c.chr  
# print any not printable control char (except \n and \r)  
print “\*\*\* #{c} \*\*\*” if (c\<32||c\>127)&&(c!=10&&c!=13)  
end  
}
