thanesh
asked on
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
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
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
write stdout to file:
"program.exe 1> c:\your_output_file"
write stderr to file:
"program.exe 2> c:\your_output_file"
ike
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
hi thanesh
You can consider executing the process with _popen() instead of CreateProcess()
Udil
You can consider executing the process with _popen() instead of CreateProcess()
Udil
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
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
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