# Shell login with IO.popen?

**URL:** <https://www.ruby-forum.com/t/shell-login-with-io-popen/107262>\
**Category:** Ruby\
**Created:** [June 19, 2007, 8:46pm UTC](https://www.ruby-forum.com/t/shell-login-with-io-popen/107262 "2007-06-19T20:46:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![goodieboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecc23a/32.png) [@goodieboy](https://www.ruby-forum.com/u/goodieboy)\
**Post date:** [June 19, 2007, 8:46pm UTC](https://www.ruby-forum.com/t/shell-login-with-io-popen/107262/1 "2007-06-19T20:46:37Z")

</div>

Hi,  
Been messing around with IO and shell/system commands. I can’t seem to  
figure out why the first example works, and the second one doesn’t.  
Would someone be so kind and explain why this happens?

# WORKS

su = IO.popen(“su - #{USERNAME}”, ‘w+’)  
su.puts PASSWORD  
su.puts ‘pwd’  
su.close\_write  
puts su.readlines

# DOESN’T WORK

login = IO.popen(“login”, ‘w+’)  
login.puts USERNAME  
login.puts PASSWORD  
login.puts ‘pwd’  
login.close\_write  
puts login.readlines

For the second one, I keep getting Invalid Login. Like it’s not really  
getting what I’m putting in to STDIN?

Thanks for helping out!
