是否可以拦截从另一个进程调用控制台? [英] Is it possible to intercept calls to console from another process?

查看:150
本文介绍了是否可以拦截从另一个进程调用控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况是,我有程序开始通过 system() CreateProcess()

The situation is that I have program started through system() or CreateProcess().

现在,是可能做的东西作为程序输出数据到控制台。我的意思是作为程序输出它。这不是等待结束,收集数据然后处理它,但只是在这个外部程序调用控制台的数据,它想打印,然后获取该数据,处理和输出别的东西控制台。

Now, is it possible to do stuff as that program outputs data into console. I mean as the program outputs it. That is not wait for the end, gather data and then process it, but just in the moment that this external program calls console with data that it wants to print, and then get hold of that data, process it and output something else on the console.

推荐答案

最简单的方法是通常使用 _popen(your_program,r ); 。这将返回一个 FILE * 你可以读取,它读取的将是任何孩子写入其标准输出。当您读取该文件上的 EOF 时,表示子进程已终止。这使得相对容易实时地读取和处理来自孩子的输出。

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.

这篇关于是否可以拦截从另一个进程调用控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆