We help IT Professionals succeed at work.

How to read output written to the console

thanesh asked
Medium Priority
Last Modified: 2011-10-03
Hi Experts,

I have a an executable file( info.exe) that I call within my program to get some information.  I used CreateProcess to execute this .exe within my program.  When executed from a command prompt, the .exe returns some data on the console.  I want my program to read that output from the .exe.   How can I do that?

Watch Question


hi thanesh,

you can always let the application output write to a file instead to the console. if you execute a program like this

"program.exe > c:\your_output_file"

the output is written into that file. then you can read it ...

hope it helps,

you can even split it into stdout and strerr - output.

write stdout to file:
"program.exe 1> c:\your_output_file"

write stderr to file:
"program.exe 2> c:\your_output_file"

Hi thanesh,
                 You need some kind of communication channel (usually one more .exe that can transmit information)between the two programs to make those two talk to one another. You cannot directly read output from a program.

The information from one exe should be packaged and sent out which is received at the other end in the same form. If you want to do this in .NET you can use the concept of remoting, in C++ I remember something called RTI(runtime infrastructure) that would take care of this communication process.

hope this helps,

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

hi thanesh

You can consider executing the process with _popen() instead of CreateProcess()


You can do the following:

- create an anonymous pipe (CreatePipe). Say the handle is then hPipe
- now create a STARTUPINFO structure and set the standard output handle = hPipe
- now create your process (CreateProcess) and as one of the params pass the startupinfo struct that you have created above
- the process will run and output will go to the pipe
- you can now read that output from the pipe use ReadFile until there is no more data left.

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.