• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1278
  • Last Modified:

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?

Thanks
0
thanesh
Asked:
thanesh
1 Solution
 
ikeworkCommented:
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,
ike
0
 
ikeworkCommented:
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"


ike
0
 
ThummalaRaghuveerCommented:
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,
Raghuveer.
0
 
udilCommented:
hi thanesh

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

Udil
0
 
gerhardschoemanCommented:
thanesh,

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.

regards
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now