0

I am running an .exe file in the command line from a Ruby script that asks the user for a Yes/No response. I would like to know how the user can interact with it in Windows environment.

I have tried all the possible options: system, backticks, %x(), Open3, Open4... and none of them work.

Some posts ([1], [2]) resolve the issue using PTY, but as to my knowledge there is no implementation of the PTY module in Windows. Any other idea?

Finfa811
  • 618
  • 1
  • 8
  • 28
  • 1
    I can't test under Windows, but maybe help: `pipe = IO.popen('your.exe', 'w+', :err => [:child, :out])` and then `pipe.each_line do |line|` and test for question, then `pipe.puts('Yes')` finally `pipe.close` – lojza Apr 17 '19 at 13:59
  • @lojza that works! Haven't tried `IO` before, thanks! – Finfa811 Apr 26 '19 at 08:14

1 Answers1

1

Seems this is working under Windows too

pipe = IO.popen('your.exe', 'w+', :err => [:child, :out])
@pipe.each_line do |line|
  if /pattern matching question/ =~ line
    break
  end
end
pipe.puts('Yes')
# another test can be here
pipe.close

Wise to use with https://ruby-doc.com/stdlib/libdoc/timeout/rdoc/Timeout.html

lojza
  • 1,823
  • 2
  • 13
  • 23