Ruby interactive shell commands

前端 未结 1 1000
南方客
南方客 2020-12-20 10:44

I want to make a ruby shell script that executes command from shell. What happens when the shell command needs the answer from a user?

For example, creating a new pl

相关标签:
1条回答
  • 2020-12-20 11:19

    Original: https://stackoverflow.com/a/6488335/2724079

    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).

    0 讨论(0)
提交回复
热议问题