Forum: Ruby IO.popen fails to pen persistent ssh connection

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Hector Q. (Guest)
on 2008-10-03 18:51
What the?
The following code(see below) works fine in a few of my ruby scripts but
fails on others with the following message:

'/scripts/ruby/testssh.rb:4: undefined method `exitstatus' for
nil:NilClass (NoMethodError)'.

I know ssh is working and I can run ssh commands to #{hostname} using
#{username} credentials. I use this exact code in other scripts from the
same workstation, ssh'ing to the same remote host and it works fine.

I've copied the following lines and pasted them unto a new file and it
still fails with the above message.

#!/usr/bin/ruby -w
ssh = IO.popen("ssh #{username}@#{hostname} -T", "w+")
status = $?
break unless (status.exitstatus == 0)

Thank you

Ara H. (Guest)
on 2008-10-03 19:54
(Received via mailing list)
On Oct 3, 2008, at 8:51 AM, Hector Q. wrote:

> #!/usr/bin/ruby -w
> ssh = IO.popen("ssh #{username}@#{hostname} -T", "w+")
> status = $?
> break unless (status.exitstatus == 0)

the process has not exited yet - $? is therefore nil.

a @
This topic is locked and can not be replied to.