Ruby Insert keystroke in shell window

Is there a way in ruby, can I enter a keystroke in the shell so that the program starts? I need to run a program in a shell through

sh " #{another program}" 

And there is "Press any key to continue" at the end of the program. How can I make him move on?

Is there something similar in ruby ​​like java

http://alvinalexander.com/java/java-robot-class-example-mouse-keystroke

+4
source share
2 answers

I think your best bet is with Autoit, it can be controlled via a COM interface like this

 require 'win32ole' ai = WIN32OLE.new("AutoItX3.Control") ai.WinWaitActive("Untitled - Notepad") 1.upto(10) do |i| ai.Send "#{i}{ENTER}" end 
+1
source

You can use Open3.popen2 to start the process and get the descriptors for stdout and stdin, and then you can "press the key" by running stdin.puts "Y" .

0
source

Source: https://habr.com/ru/post/1443074/


All Articles