有可能放一个钩子捕获消息发送到控制台的子进程? [英] It is possible to put a hook catching messages that are send to console by child process?

查看:293
本文介绍了有可能放一个钩子捕获消息发送到控制台的子进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我开始一个普通的控制台程序,然后在其中创建另一个进程。接下来,子进程尝试在父进程所拥有的控制台上写入内容。

So I start an ordinary console program and then create another process within it. Next the child process tries to write something onto console that is owned by parent process.

这是可能的,在这个控制台上,当子进程尝试写一个文本我可以在这个文本上搜索和替换,并将其更改到控制台。

Is it possible to put a hook on this console so when child process tries to write some text I could do search and replace on this text and put it changed onto the console.

(我知道这是可能的管道,但在这里我特别要求做因为一些程序的行为有所不同,如果他们发现他们附加到管道,而不是控制台。)

(I know it is possible with pipes, but here I ask specifically of doing it at the console level, because some programs behave differently if they see they are attached to pipes instead of console.)

SetWindowsHookEx 与我的问题有关?

推荐答案

为了避免混淆,Windows消息不涉及这样挂钩是完全错误的概念。

Just to avoid confusion, windows messages aren't involved with this so hooking is entirely the wrong concept.

如果要更改写入STDOUT的子进程数据,则需要创建自己的管道,创造它。这允许您从其中读取数据,根据需要更改,然后自己打印到STDOUT。没有办法拦截直接写入控制台的数据。

If you want to change the child processes data written to STDOUT, you'll need to create your own pipes that you pass to the process when creating it. This allows you to read the data from it, change as you require then print to STDOUT yourself. There is no way to intercept data written direct to the console.

这篇关于有可能放一个钩子捕获消息发送到控制台的子进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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