[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: ssh / popen / stdin weirdness

Doug Phillips

5/19/2007 2:12:00 AM

> -----Original Message-----
> From: Mike Cahill [mailto:mike.cahill@comcast.net]
> Sent: Friday, May 18, 2007 8:56 PM
> To: ruby-talk ML
> Subject: ssh / popen / stdin weirdness
>
> Sorry I can't figure out how to find the cause of this
> myself. I'm sure there's some article somewhere I'm not finding.
>
> on RHEL4 u3, ruby 1.8, create:
>
> ===
> app.rb:
>
> my_pipe = IO.popen("ssh foreign-host 'cat filename')
> file_contents = my_pipe.read
> my_pipe.close
>
> inp = $stdin.read
> puts "returning " + inp
>
> ====
>
> Run this app from this host (call it ServerB):
> ruby app.rb <<EOF
> hi there
> EOF
>
> You get "returning hi there", as expected.
>
> ----
> Now, from ServerA (public keys have been pushed), run:
>
> ssh ServerB 'ruby app.rb' <<EOF
> hi there
> EOF
>
> it fails, in that inp receives nothing from $stdin.
> ----
>
> now, go back to app.rb, remove the first three lines so
> there's no call to IO.pipe.
>
> run it again, it works.
>
> why does $stdin get "moved" when the app is called remotely
> and opens a pipe?

SSH doesn't fork a TTY when a command is given. Try calling ssh with
the -t flag.
-Doug