读取应用程序的输出 [英] Read Output of an application
问题描述
我有一个应用程序,我想从中运行另一个基于控制台的 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屋!