读取应用程序的输出 [英] Read Output of an application

查看:26
本文介绍了读取应用程序的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我想从中运行另一个基于控制台的 exe 并读取该控制台应用程序的输出?假设控制台应用程序是使用 printf 编写它的第三方 exe.

I have an application from where I suppose to run another console based exe and read the output of that console application? Assume the console application is third party exe which writing it using printf.

推荐答案

使用 CreateProcess() 运行控制台应用程序,然后可以使用 STARTUPINFO 结构体来指定您自己的 STDIN/OUT/ERR 句柄供控制台使用.为此,通过 CreatePipe() 创建匿名管道,然后您可以根据需要使用 ReadFile()WriteFile() 读/写管道.

Use CreateProcess() to run the console app, then you can use the STARTUPINFO struct to specify your own STDIN/OUT/ERR handles for the console to use. Create anonymous pipes via CreatePipe() for that purpose, then you can read/write the pipes using ReadFile() and WriteFile() as needed.

MSDN 上有一个例子:

There is an example on MSDN:

创建子进程带有重定向输入和输出

这篇关于读取应用程序的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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