"Mike Cahill" <mike.cahill / comcast.net> writes:
> 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.
What's happening is that the standard input is getting read by the ssh
process itself, if the standard input is ready when the ssh process is
running.
Try this on ServerB: (i.e. where you ran it locally and it succeeded)
echo hi there | ruby abb.rb
I'm betting that you won't get "hi there" being returned, because "hi
there" will end up as standard input to the ssh process.
To fix this, change this line:
my_pipe = IO.popen("ssh foreign-host 'cat filename')
into:
my_pipe = IO.popen("ssh foreign-host 'cat filename' < /dev/null")
Now ssh won't pull on your standard input stream. If you prefer to
put the bit of input redirection at the front of the line, you can
also do something like this:
my_pipe = IO.popen("echo|ssh foreign-host 'cat filename'")
or even this, though I think it's less portable:
my_pipe = IO.popen("</dev/null ssh foreign-host 'cat filename'")
Now, why this makes a difference running it locally versus remotely
I'm not entirely sure, especially since I'd think that a here document
would be sent all at once even to a local process, but when I was
running it locally just by typing lines and then control-D, the line
returned was the first line typed after the ssh process had completed.
--
s=%q( Daniel Martin -- martin / snowplow.org
puts "s=%q(#{s})",s.to_a.last )
puts "s=%q(#{s})",s.to_a.last