[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

IO.popen and ssh

Paul Lynch

9/11/2007 3:45:00 PM

I've been having some trouble using IO.popen to control an ssh process
(and also mysqldump) on Linux. My understanding is that if I do:
p = IO.popen('ssh mymachine')
then the input and output of the ssh subprocess should be accessible via
p. However, when I try that in an irb shell, the ssh process
immediately takes over the standard input and output of irb, and I get
an "Enter password:" prompt. I have to hit control-c to get back to the
irb prompt.

Is there a workaround for this? Or should I be doing this a different
way? Thanks,
--Paul
--
Posted via http://www.ruby-....

4 Answers

Edwin van Leeuwen

9/11/2007 4:00:00 PM

0

Paul Lynch wrote:
> Is there a workaround for this? Or should I be doing this a different
> way?

Why not use Net::SSH to connect directly from ruby?
http://net-ssh.rubyforge.org/chapter...
--
Posted via http://www.ruby-....

Paul Lynch

9/11/2007 4:12:00 PM

0

That looks much better-- thanks!

Edwin Van leeuwen wrote:
>
> Why not use Net::SSH to connect directly from ruby?
> http://net-ssh.rubyforge.org/chapter...

--
Posted via http://www.ruby-....

Konrad Meyer

9/11/2007 6:32:00 PM

0

Quoth Edwin Van leeuwen on Tuesday 11 September 2007 08:59:39 am:
> Paul Lynch wrote:
> > Is there a workaround for this? Or should I be doing this a different
> > way?
>
> Why not use Net::SSH to connect directly from ruby?
> http://net-ssh.rubyforge.org/chapter...

Because at least in my experience, it doesn't work? :D

--
Konrad Meyer <konrad@tylerc.org> http://konrad.sobertil...

ara.t.howard

9/11/2007 7:34:00 PM

0


On Sep 11, 2007, at 9:44 AM, Paul Lynch wrote:

> I've been having some trouble using IO.popen to control an ssh process
> (and also mysqldump) on Linux. My understanding is that if I do:
> p = IO.popen('ssh mymachine')
> then the input and output of the ssh subprocess should be
> accessible via
> p. However, when I try that in an irb shell, the ssh process
> immediately takes over the standard input and output of irb, and I get
> an "Enter password:" prompt. I have to hit control-c to get back
> to the
> irb prompt.
>
> Is there a workaround for this? Or should I be doing this a different
> way? Thanks,

ssh requires a pty to read the password. note that this is NOT the
same as STDIN, which is what you get with IO.popen. you need to use
the built-in pty lib to control ssh that way and it's still fraught
with peril. it's much, much, much, much better to setup ssh keys for
password-less access (no passwords in scripts), and to spawn a simple
command, such as /bin/sh, on the remote end to read pre-generated
commands (a script).

regards.

a @ http://draw...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama