i am trying to fork a process to run a simple script which requires a
username and password. i made a test case with a simple bash script
and a simple ruby script; however, the ruby script hangs in
stdout.read???
i am new to ruby, so i am assuming i am doing something wrong can
anyone help?
bash script
#! /bin/bash
sleep 3
echo -n "username: "
read -e USERNAME
echo -n "password: "
read -e PASSWORD
echo ârunning your script now for $USERNAME with password $PASSWORDâ
echo âdoing somethingâŚâ
sleep 3
echo âend doing somethingâŚquitingâ
exit 0
ruby script
require âopen3â
cmd = â./myScript.bashâ
#cmd = âgpg --list-keysâ
begin
stdin, stdout, stderr = Open3.popen3 cmd
done = 0
until done == 1
begin
line = stdout.read
print â#{line}â
puts line.eql?("username: ")
if line.eql?("username: ")
puts âmyuserâ
stdin.write âmyuser\nâ
line = stdout.read
if line.eql?("password: ")
puts âmypasswordâ
stdin.write âmypassword\nâ
done = 1
end
puts âim here!â
end
end
end
end