"Answering a cli prompt in ruby with open3?" is a possible duplicate question but it has no answer.
I need to write a program which compiles and executes a C program, gives inputs and returns the output. So far I came up with this:
For single input:
Open3.popen3('one.exe') do |stdin, stdout, stderr|
stdin.puts "45\n"
STDOUT.puts stdout.gets
end
and the outputs is:
Enter the temperature in degrees fahrenheit: The converted temperature is 7.222222
For two or more inputs:
Open3.popen3('two.exe') do |stdin, stdout, stderr|
stdin.puts "45 45"
# This line works the same as the previous one.
# stdin.puts "45\r\n45"
stdin.close
STDOUT.puts stdout.gets
end
and the output is:
Enter first number: Enter second number: Sum is 90
The problem is, I did not get back the inputs I put in.
Is there a way I can correct it or maybe a better way to do this?