From: 7stud -- Date: 2008-05-19T10:06:51+09:00 Subject: Re: Needing to pipe commands to automate program Ruggershawn wrote: > Hello, > > I am fairly new in the ruby language. I have a ruby program that > needs to be automated. Every time I run this program you have to > manually type in the questions. > > Examples: Are you using 32/64 bit? > Enter the path where you wish to install? > > What I am trying to find a way where I can create a script to pipe the > answers from a flat file so this can be done automatically. > > Anyone have any ideas? > > Thanks! #original program: r1test.rb puts "Enter 32 or 64 bit:" STDOUT.flush answer1 = gets.strip.chomp puts "Enter the path where you wish to install:" STDOUT.flush answer2 = gets.strip.chomp puts "Your answers were:" puts answer1 puts answer2 STDOUT.flush ---------- #driver program: r2test.rb pipe = IO.popen("ruby r1test.rb", "w+") f = File.open("answers.txt") pipe.gets #Enter 32 or 64 bit: pipe.puts(f.gets.chomp) pipe.gets #Enter the path: pipe.puts(f.gets.chomp) puts pipe.gets, pipe.gets, pipe.gets puts puts "Hit enter to end program" gets ---------------- $ ruby r2test.rb Your answers were: 32 ./test_programs Hit enter to end program -- Posted via http://www.ruby-forum.com/.