Click to See Complete Forum and Search --> : Read from a Console


whterbtobj
June 15th, 2009, 12:35 PM
How can I read output from a console?
I want to run a console program and then read outputs from it.

JVene
June 15th, 2009, 02:32 PM
This depends on how you want to structure it, but you're asking about a typical Unix utility concept. Using cin and count, simply issue something like this at a command line:

program1 | program2

This is a "pipe" - the output of program1 is sent to the input of program2.

whterbtobj
June 15th, 2009, 03:26 PM
I dont want to pipe.

I am building a Windows application that, at some point, calls a separate process (a command line application). The program takes quite some time to complete (about 5 minutes or more). How can I capture the console app's output in order to show it (in a textbox for instance) in my windows application?

JVene
June 15th, 2009, 03:36 PM
Search for popen, either MSDN, standard C runtime library documentation, or google.

What you'll get is a reference to opening a pipe between your application and the console app you're launching.

whterbtobj
June 16th, 2009, 12:00 PM
I tried popen but it won't let me read the output in real time.
I've to wait for the process to complete.

JVene
June 16th, 2009, 01:27 PM
You could try CreateProcess, or read from there to the tributaries on the subject in MSDN