I'm trying to answer different questions from external script using Ruby.
This is working code
Open3.popen3("cp -i 1 0") {|i,o,e,p|
i.write "y\n"
i.close
o.read.split("\n").each {|l| puts l }
}
But, what if external command asks a question and then asks another question, if first answer was true?
Example code
Open3.popen3("/sbin/parted /dev/sda rm 1") {|i,o,e,p|
i.write "n\n"
i.close
o.read.split("\n").each { |l| puts l }
exit_status = p.value
puts "Exit status: " + (exit_status.success? ? 'succeeded' : 'failed')
}
Its always failed. Doesn't matter if answer y\n
or n\n
. When I hit n
in the console, parted stops and partition stays as is. When I hit y
, I receive another confirmation where I should answer with "Ignore/Cancel" (i
or c
). How to answer on external call correctly? First "yes", second "ignore" (y
then i
)?