M
mpurdy
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
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