# Net-ssh : popen3

**URL:** <https://www.ruby-forum.com/t/net-ssh-popen3/152498>\
**Category:** Ruby\
**Created:** [November 4, 2008, 4:48pm UTC](https://www.ruby-forum.com/t/net-ssh-popen3/152498 "2008-11-04T16:48:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Philip\_MSSS\_ller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/eb8c5e/32.png) [@Philip\_MSSS\_ller](https://www.ruby-forum.com/u/Philip_MSSS_ller)\
**Post date:** [November 4, 2008, 4:48pm UTC](https://www.ruby-forum.com/t/net-ssh-popen3/152498/1 "2008-11-04T16:48:37Z")

</div>

Hi everybody,

I want to start and interact with a process on another machine.  
After reading example 20.10 in “The Ruby Cookbook” and doing some  
internet  
research I decided to use net/ssh and popen3.  
Sadly, it does not work - it just doesn’t do anything noticeable, it  
doesn’t even terminate.

Here’s my code:

----------- CODE ----------------

require ‘rubygems’  
require ‘net/ssh’

def run\_remotely(command)  
Net::SSH.start(“localhost”, “tester”, :password =\> “pass”) do  
|session|  
session.process.popen3(command) do |stdin, stdout, stderr|  
yield stdin, stdout, stderr  
end  
end  
end

run\_remotely(‘cat’) do |stdin, stdout, stderr|  
stdin.puts ‘Line one.\n’  
end

----------- /CODE ----------------

Why doesn’t this work?

Thanks,

Philip

P.s.:  
I have successfully used channel.exec to execute “ls”, but it doesn’t  
seem  
like it allows two-way communication.

---

<div class="post-metadata">

**Author:** ![Philip\_MSSS\_ller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/eb8c5e/32.png) [@Philip\_MSSS\_ller](https://www.ruby-forum.com/u/Philip_MSSS_ller)\
**Post date:** [November 4, 2008, 4:48pm UTC](https://www.ruby-forum.com/t/net-ssh-popen3/152498/2 "2008-11-04T16:48:37Z")

</div>

On Tue, 04 Nov 2008 16:09:05 +0100, Philip MÃ¼ller [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

Sorry…

> run\_remotely(‘cat’) do |stdin, stdout, stderr|  
> stdin.puts ‘Line one.\n’  
> end

is supposed to be

run\_remotely(‘cat’) do |stdin, stdout, stderr|  
stdin.puts ‘Line one.\n’  
puts stdout.read  
end

Regards

Philip
