From: mpurdy Date: 2011-04-09T10:45:23+09:00 Subject: Re: reading and writing to child process with streams in ruby On Apr 8, 4:03 am, "Y. NOBUOKA" wrote: > Hi, > > Using IO#readpartial [1] instead of IO#read, you'll see the ruby > script run as expected. > However, I don't know if this is the best way or not. > > [1]http://www.ruby-doc.org/core/classes/IO.html#M000917 > > ---------------------------------------------------------------------- > ruby script > ---------------------------------------------------------------------- > require 'open3' > > cmd = "./myScript.bash" > #cmd = "gpg --list-keys" > begin > stdin, stdout, stderr = Open3.popen3 cmd > > p stdin, stdout, stderr > done = 0 > until done == 1 > begin > # using IO#readpartial instead of IO#read > line = stdout.readpartial( 4096 ) > puts "#{line}" > puts line.eql?("username: ") > if line.eql?("username: ") > puts "myuser" > stdin.write "myuser\n" > # using IO#readpartial instead of IO#read > line = stdout.readpartial( 4096 ) > if line.eql?("password: ") > puts "mypassword" > stdin.write "mypassword\n" > done = 1 > end > puts "im here!" > end > rescue => err > p err > end > end > end > > -- > 信岡 裕也 (NOBUOKA Yuya) thanx that did work; however, i after doing more research i agree this is not the best way. i am a c/c++, java/groovy guy...this ruby stuff is all new to me; however, after day one; i like it:-)