Shell login with IO.popen?


#1

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!