Discussion:
How Do I Capture Screen Text Into a Batch File?
(too old to reply)
Peter
2022-08-26 17:40:41 UTC
Permalink
How do I “capture” text on the screen into a variable in a batch file? Specifically, this is what I need to do:

1. The batch file will issue a command to check the status of something in the PC.
2. The PC will respond with about 6 lines of text on the screen (the 3rd line is blank).
3. I need to capture that text.
4. The batch file will then check the first three words on the 4th line of text and will then GOTO depending on the first three words.

I need some help with steps 3 & 4.

For step 3, how do I capture that text as it is displayed on the screen? I assume it goes into a variable but I don’t know how to get that screen text into a variable.

For step 4, how do I get the batch file to look at the first three words on line four?

Thanks!
Zaidy036
2022-08-26 19:13:10 UTC
Permalink
Post by Peter
1. The batch file will issue a command to check the status of something in the PC.
2. The PC will respond with about 6 lines of text on the screen (the 3rd line is blank).
3. I need to capture that text.
4. The batch file will then check the first three words on the 4th line of text and will then GOTO depending on the first three words.
I need some help with steps 3 & 4.
For step 3, how do I capture that text as it is displayed on the screen? I assume it goes into a variable but I don’t know how to get that screen text into a variable.
For step 4, how do I get the batch file to look at the first three words on line four?
Thanks!
Command in #1 should direct output to a file (CMD > F:\test.txt) and
then use FINDSTR if text in line 4 is consistent or extract that line
and use SET /P _GO=<[line 4].
Kenny McCormack
2022-08-27 13:19:18 UTC
Permalink
How do I capture text on the screen into a variable in a batch file?
1. The batch file will issue a command to check the status of
something in the PC.
2. The PC will respond with about 6 lines of text on the screen (the 3rd line is blank).
3. I need to capture that text
4. The batch file will then check the first three words on the 4th
line of text and will then GOTO depending on the first three words.
I need some help with steps 3 & 4.
For step 3, how do I capture that text as it is displayed on the screen? I
assume it goes into a variable but I dont know how to get that screen text
into a variable.
For step 4, how do I get the batch file to look at the first three words on line four?
Thanks!
For this question to be even mildly interesting, it has to be assumed that
simple redirection (i.e., program > file) and then parsing the resulting
file is not an option. This can happen in the real world with programs
that, for whatever reason(s), insist on writing to the screen and won't
send their output to a file via simple redirection.

Assuming this to be the case, then you will have to come up with a way to
pick off the information from the screen itself. AFAIK, there is no way to
do this in pure batch, but it is easy enough done using some "real"
scripting language; one that can access and execute the
ReadConsoleOutputCharacters() API. I know how to do this (and have done
so) in WinBatch. I'm sure some enterprising soul will come along and tell
you how to do it in VBScript (or whatever they are calling it nowadays).
--
People who want to share their religious views with you
almost never want you to share yours with them. -- Dave Barry
Robert Prins
2022-08-27 22:13:54 UTC
Permalink
Post by Kenny McCormack
How do I capture text on the screen into a variable in a batch file?
1. The batch file will issue a command to check the status of
something in the PC.
2. The PC will respond with about 6 lines of text on the screen (the 3rd line is blank).
3. I need to capture that text
4. The batch file will then check the first three words on the 4th
line of text and will then GOTO depending on the first three words.
I need some help with steps 3 & 4.
For step 3, how do I capture that text as it is displayed on the screen? I
assume it goes into a variable but I dont know how to get that screen text
into a variable.
For step 4, how do I get the batch file to look at the first three words on line four?
Thanks!
For this question to be even mildly interesting, it has to be assumed that
simple redirection (i.e., program > file) and then parsing the resulting
file is not an option. This can happen in the real world with programs
that, for whatever reason(s), insist on writing to the screen and won't
send their output to a file via simple redirection.
Assuming this to be the case, then you will have to come up with a way to
pick off the information from the screen itself. AFAIK, there is no way to
do this in pure batch, but it is easy enough done using some "real"
scripting language; one that can access and execute the
ReadConsoleOutputCharacters() API. I know how to do this (and have done
so) in WinBatch. I'm sure some enterprising soul will come along and tell
you how to do it in VBScript (or whatever they are calling it nowadays).
I've done this, on pure DOS, in the past. The key is to read the video segment
with debug, move the read data into a buffer left into the start of the debug
script, and writing out that buffer as a text file.

Robert
--
Robert AH Prins
robert(a)prino(d)org
The hitchhiking grandfather - https://prino.neocities.org/
Some REXX code for use on z/OS - https://prino.neocities.org/zOS/zOS-Tools.html
Anton Shepelev
2022-08-27 20:17:58 UTC
Permalink
Robert,

the message of yours to which I reply contains:
Date: Sat, 27 Aug 2022 22:13:54 +0000
The current GMT being 20:17, you must be a guest
from the future.
--
() ascii ribbon campaign -- against html e-mail
/\ http://preview.tinyurl.com/qcy6mjc [archived]
Kenny McCormack
2022-08-27 23:30:18 UTC
Permalink
In article <tedqdd$c5e4$***@dont-email.me>,
Robert Prins <***@prino.org> wrote:
...
Post by Robert Prins
I've done this, on pure DOS, in the past. The key is to read the video
segment with debug, move the read data into a buffer left into the start
of the debug script, and writing out that buffer as a text file.
It's not that easy under modern Windows, but the principle is the same.

As I mentioned, there is a specific Window API for it.
--
Never, ever, ever forget that "Both sides do it" is strictly a Republican meme.

It is always the side that sucks that insists on saying "Well, you suck, too".
Loading...