I'm trying to write a little lib which generates a keypair using open4, is this the best way of dealing with system calls with multiple prompts?
require 'rubygems'
require 'open4'
Open4::popen4("sh") do |pid, stdin, stdout, stderr|
stdin.puts "openssl genrsa -des3 -out tmp_priv.pem 2048"
stdin.puts "1234"
stdin.puts "1234"
stdin.close
end
Open4::popen4("sh") do |pid, stdin, stdout, stderr|
stdin.puts "openssl rsa -in tmp_priv.pem -out tmp_public.pem -outform PEM -pubout"
stdin.puts "1234"
stdin.close
end
Open4::popen4("sh") do |pid, stdin, stdout, stderr|
stdin.puts "cat tmp_priv.pem tmp_public.pem >> tmp_keypair.pem"
stdin.close
end