Ruby - 在 Windows 环境中调用命令并与 shell 交互

Ruby - Calling commands and interact with shell in Windows environment

我是 运行 来自 Ruby 脚本的命令行中的 .exe 文件,要求用户提供 Yes/No 响应。我想知道用户如何在 Windows 环境中与之交互。

我已经尝试了所有可能的选项:system、反引号、%x()、Open3、Open4...其中 none 有效。

一些帖子 ([1], ) 使用 PTY 解决了这个问题,但据我所知 Windows 中没有 PTY 模块的实现。还有其他想法吗?

这似乎也在 Windows 下工作

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

明智地与https://ruby-doc.com/stdlib/libdoc/timeout/rdoc/Timeout.html

一起使用