How to read output written to the console

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?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.