Shell login with IO.popen?

G

goodieboy

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top