Is it possible to intercept calls to console from another process?

浪尽此生 提交于 2019-12-06 15:36:04

The easiest way is usually to start the program with _popen(your_program, "r");. That will return a FILE * you can read from, and what it reads will be whatever the child writes to its standard output. When you read EOF on that file, it means the child process has terminated. This makes it relatively easy to read and process the output from the child in real time.

On Linux, create a named pipe:

system("mkfifo pipename")

Then open the pipe in the first program, and start the program with:

system("program > pipename")

I'm not sure how to do this on Windows.

Call AllocConsole before creating child process, or use AttachConsole(ChildPID) function (in parent process). After that, you may use any ReadConsoleXXX or WriteConsoleXXX functions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!