Ruby windows command retrieves previous lines

Is it possible to edit content already written on the command line using Ruby?

So, for example, let's say I wrote 10 lines in STDOUT, can I move the cursor, say, lime 5, and rewrite only this line?

Thanks.

+4
source share
1 answer

Yes, you can in Windows Vista 7 and possibly 8, as well as in some third-party advanced command interpreters, such as 4NT and Take Command, you can recall previous commands using the up key, execute the line. I don't understand what Ruby has to do with this. If you want to allow Ruby-type keystrokes in the console, which is possible using Active-X automatic control.

EDIT: here's a sample using Autoit to edit the console, downlaod and install it first, and then run the following script. To make sure that the script does not interact with other open consoles, I copied mu cmd.exe to cmd2.exe, which starts first.

require 'win32ole' title = "C:\\Windows\\System32\\cmd2.exe" STDOUT.sync = true ai = WIN32OLE.new("AutoItX3.Control") ai.winwait(title) ai.WinActivate(title, "") ai.Send "cls{ENTER}" 1.upto(4) do |i| ai.Send "line#{i}{ENTER}" end 1.upto(4) do |i| ai.Send "{UP}" sleep 1 end ai.Send "line one {ENTER}" 
+2
source

All Articles