0

Is it possible to read what's currently displayed on the windows terminal pragmatically using any available API?

For example, I've got an app that tail's some log files. I'd like to be able to hit a key and open a text editor at the line that is currently being viewed. The problem is the terminal also has scroll bars.

hookenz
  • 36,432
  • 45
  • 177
  • 286
  • Do you mean a standard console screen buffer? See [`ReadConsoleOutputW`](https://learn.microsoft.com/en-us/windows/console/readconsoleoutput). – Eryk Sun Sep 17 '19 at 09:04
  • Thanks @ErykSun that seems to be exactly what I'm after – hookenz Sep 18 '19 at 00:16

1 Answers1

0

Not easy. Perhaps you could capture the screen and use OCR to identify its contents, or make a shortcut to some sort of macro that selects all the screen and copies the text. But there is no API available to perform the task you ask.

Of course, you can tee the command you're running in the console to a file, and open such file with an editor whenever you like, however it will show the full output of the command and not the visible part. If you like more information on that topic, it is answered in SO - Displaying Windows command prompt output and redirecting it to a file .

Marc Sances
  • 2,402
  • 1
  • 19
  • 34