Needing to pipe commands to automate program

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!

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

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!

This works too:

#original program: r1test.rb

puts “Enter 32 or 64 bit:”
answer1 = gets.strip.chomp

puts “Enter the path where you wish to install:”
answer2 = gets.strip.chomp

File.open(‘output.txt’, ‘w’) do |f|
f.puts(“Your answers were:”)
f.puts answer1
f.puts answer2
end

Just be aware that popen() hijacks stdin and stdout in the original
program–directing the original program’s input and output to the IO
object created in the driver program. If your original program writes
some results to a file, then that won’t be an issue.

7stud – wrote:

This works too:

#original program: r1test.rb

puts “Enter 32 or 64 bit:”
answer1 = gets.strip.chomp

puts “Enter the path where you wish to install:”
answer2 = gets.strip.chomp

File.open(‘output.txt’, ‘w’) do |f|
f.puts(“Your answers were:”)
f.puts answer1
f.puts answer2
end

Just be aware that popen() hijacks stdin and stdout in the original
program–directing the original program’s input and output to the IO
object created in the driver program. If your original program writes
some results to a file, then that won’t be an issue.

Whoops. Here’s the driver program:

#driver program:

pipe = IO.popen(“ruby r1test.rb”, “w+”)
f = File.open(“data.txt”)

pipe.puts(f.gets.chomp)
pipe.puts(f.gets.chomp)

puts
puts “Hit enter to end program”
gets

Hey Thanks for the reply! It worked great!

Now I am wondering how to output the standard out to the screen? Right
now I run my ruby program and cant see anything being logged.