如何处理C ++重定向进程的输出 [英] How to handle output of C++ redirected process

查看:67
本文介绍了如何处理C ++重定向进程的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究C ++应用程序,但遇到了问题。



请参阅下面我的申请的简要说明:

有两个过程可以协同工作。主进程(应用程序A)调用第二个进程(应用程序B),它是第一个进程的子进程。



应用程序A:主要应用程序:带QT的C ++应用程序界面和进度条。它使用CreateProcess调用另一个进程。



应用程序B:C ++可执行文件。这个exe在stdout上生成输出消息,如:

PROGRESS 1%

PROGRESS 20%

...

进展100%



我想做什么:

我想用应用程序A启动应用程序B.我的意思是我启动整个应用程序,应用程序A运行并创建另一个启动应用程序B的进程。我想捕获B的输出并更新应用程序A的进度条。

我已经实现了重定向系统在这篇文章中解释:

https://support.microsoft.com/en-us/kb/190351



它有效但是问题是当exe终止时处理B的输出消息,而不是在执行期间处理。

我想在执行期间处理B的输出消息。我正在考虑使用重定向系统使用命名管道。

您怎么看?有什么建议?任何想法?



提前谢谢。

I am working on a C++ application and I am encountered a problem.

See below a brief description of my application :
There are two processes which work together. The main process (application A ) calls the second one (application B) which is the child of the first one.

Application A : Main application : C++ application with QT interface and a progress bar. It calls an another process with using CreateProcess.

Application B : C++ executable. This exe generates output messages on stdout like :
PROGRESS 1%
PROGRESS 20%
...
PROGRESS 100%

What I would like to do :
I would like to launch the application B with the application A. I mean when I launch the whole application, application A runs and creates another process which launchs the application B. I would like to catch the output of B and update the progress bar of application A.
I have implemented the redirected system explained on this article :
https://support.microsoft.com/en-us/kb/190351

It works but the problem is that the output messages of B are processed when the exe is terminated and not during the execution.
I would like to process the output messages of B during its execution. I was thinking to use the redirected system with using named pipes.
What do you think? Any advice ? any idea ?

Thank you in advance.

推荐答案

我会选择命名管道作为desrcibed in这个文章



代码:应用程序是同时运行,还是启动程序(A)等待B终止。
I would go for named pipes as desrcibed in this article.

On your code: Are the apps running at the same time, or is the launcher (A) waiting for the termination of B.


这篇关于如何处理C ++重定向进程的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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