# IO.popen fails to pen persistent ssh connection

**URL:** <https://www.ruby-forum.com/t/io-popen-fails-to-pen-persistent-ssh-connection/150091>\
**Category:** Ruby\
**Created:** [October 3, 2008, 4:51pm UTC](https://www.ruby-forum.com/t/io-popen-fails-to-pen-persistent-ssh-connection/150091 "2008-10-03T16:51:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hector](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/43a26b/32.png) [@hector](https://www.ruby-forum.com/u/hector)\
**Post date:** [October 3, 2008, 4:51pm UTC](https://www.ruby-forum.com/t/io-popen-fails-to-pen-persistent-ssh-connection/150091/1 "2008-10-03T16:51:25Z")

</div>

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)

Help…  
Thank you

Hector

---

<div class="post-metadata">

**Author:** ![hector](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/43a26b/32.png) [@hector](https://www.ruby-forum.com/u/hector)\
**Post date:** [October 3, 2008, 5:54pm UTC](https://www.ruby-forum.com/t/io-popen-fails-to-pen-persistent-ssh-connection/150091/2 "2008-10-03T17:54:27Z")

</div>

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 @ [http://codeforpeople.com/](http://codeforpeople.com/)
