Capturing output from program in console

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Capturing output from program in console

Post by mightycpa » Sun Feb 12, 2023 7:10 pm

Hi,

I've never tried this before, but I have a dos program that returns data to the console periodically as it is running. I have created a small batch file to simulate its output:

Code: Select all

CLS
ECHO OFF
FOR /L %%A IN (1,1,10) DO (
  TIMEOUT /T 5 >NUL
  ECHO %%A
)
ECHO DONE
The batch file output looks like this, it takes a little less than a minute, 5 seconds between each count:
Image

Obviously, my program's output is a little more complex, but this is the idea. Capture a periodic string of data from the console. What I want to do is to capture each line of data as it appears and then process it while I wait for the next one.

I don't want to output to a file if I can help it.

Can I repeatedly capture the new output in a variable with the RunProgram command or something else?

Thanks
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Capturing output from program in console

Post by Grovkillen » Sun Feb 12, 2023 8:33 pm

It's possible output continously to a file but since you're not interested in that you're as far as I can tell out of luck. I have proposed something like that though... Here>>
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Capturing output from program in console

Post by JRL » Mon Feb 13, 2023 5:28 pm

Open a command prompt.
Select "Properties" from the menu when you right click the command icon in the upper left corner.
Make sure "Use legacy console..." is unchecked.
Above that, make sure "Enable Ctrl Key Shortcuts" is checked.
Close save and close any command windows you have open.

From now forward you can:
Focus the command window Press ctrl, Send>a, Release ctrl to highlight all text in the window.
Press Press ctrl, Send>c, Release ctrl to copy the selected text.
Use getclipboard> to set that text to a variable.
Then parse the text however you need.

Not what you wanted but the best I know of.

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Capturing output from program in console

Post by Grovkillen » Mon Feb 13, 2023 5:53 pm

Yeah, using clipboard is a very slippery slope. I tend to not use it these days because it.
Let>ME=%Script%

Running: 15.0.27
version history

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Capturing output from program in console

Post by mightycpa » Fri Feb 24, 2023 4:51 am

Hi, JRL, thanks for the suggestion. In the end, I decided to create a small ram drive, and I wrote my file to there, and read and parsed the answer. Because the drive is in memory, it's fast, it won't wear a groove in my hard drive, and so that's an acceptable substitute for reading from the console.

I appreciate the suggestion.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts