Pipe output(stdout) from running process Win32Api

后端 未结 3 1376
南方客
南方客 2020-12-09 09:36

I need to get (or pipe) the output from a process that is already running, using the windows api.

Basically my application should allow the user to select a window t

3条回答
  •  星月不相逢
    2020-12-09 10:13

    The cleanest way of doing this without causing any ill effects, such that may occur if you used the method Adam implied of swapping the existing stdout handle with your own, is to use hooking.

    If you inject a thread into the existing application and swap calls to WriteFile with an intercepted version that will first give you a copy of what's being written (filtered by handle, source, whatever) then pass it along to the real ::WriteFile with no harm done. Or you can intercept the call higher up by only swapping out printf or whichever call it is that the software is using (some experimentation needed, obviously).

    HOWEVER, Adam is spot-on when he says this isn't what you want to do. This is a last resort, so think very, very carefully before going down this line!

提交回复
热议问题