更新时间:2022-12-03 11:22:04
原文:https://***.com/a/6488335/2724079
这也可以通过 IO.expect 来实现
This can also be accomplished with IO.expect
require 'pty'
require 'expect'
PTY.spawn("play new calimero") do |reader, writer|
reader.expect(/What is the application name/)
writer.puts("\n")
end
这会等待生成的进程显示应用程序名称是什么",并且当它看到打印定义的字符串(新行)时.
This waits for the spawned process to display "What is the application name" and when it sees that prints a defined string (new line).