0

I have an application from where I suppose to run another console based exe and read the output of that console application? Assume the console application is third party exe which writing it using printf.

Abhineet
  • 5,320
  • 1
  • 25
  • 43
CrazyC
  • 1,840
  • 6
  • 39
  • 60
  • 2
    You can do this with `CreateProcess` - see http://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspx – benjymous Dec 19 '13 at 10:11
  • Currently I am using CreateProcess to launch third party exe but the link say I have make changes in the childExe also. Means here in Third party exe which is not possible. – CrazyC Dec 19 '13 at 10:13
  • 1
    @CrazyC AFAIK, you don't need to modify the child exe. Where does it say that? (The bit with pipe communication in the example is for the specific example - the `printf` should also show up in the parent.) – molbdnilo Dec 19 '13 at 10:53

1 Answers1

0

Use CreateProcess() to run the console app, then you can use the STARTUPINFO struct to specify your own STDIN/OUT/ERR handles for the console to use. Create anonymous pipes via CreatePipe() for that purpose, then you can read/write the pipes using ReadFile() and WriteFile() as needed.

There is an example on MSDN:

Creating a Child Process with Redirected Input and Output

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770