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?

2
  • 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 Commented Apr 17, 2019 at 13:59
  • @lojza that works! Haven't tried IO before, thanks! Commented Apr 26, 2019 at 8:14

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.