从另一个执行和捕获一个程序 [英] Execute and Capture one program from another

查看:173
本文介绍了从另一个执行和捕获一个程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C:



中的win32编程中在另一个win32程序中执行win32控制台程序的最佳方式是,启动执行的程序捕获输出?现在我把程序重定向输出到一个文件,但我相信我必须能够打开某种管道?

解决方案

使用 CreateProcess Win32 API启动子进程。



传递给它一个的结构 hStdInput , hStdOutput hStdError 句柄设置为打开的文件句柄内存映射文件应该工作)。你不需要指定所有三个,你可以重定向只有你真正需要的;最常见的情况是 hStdOutput



如果要与子进程通信> hStdInput ),您需要等待它初始化,方法是调用 WaitForInputIdle


In win32 programming in C:

Whats the best way to execute a win32 console program within another win32 program, and have the program that started the execution capture the output? At the moment I made the program redirect output to a file, but I am sure I must be able to open some sort of pipe?

解决方案

Use the CreateProcess Win32 API to start the child process.

Pass to it a STARTUPINFO structure with hStdInput, hStdOutput and hStdError handles set to file handles you opened (either real files or memory mapped files should work). You don't need to specify all three, you can redirect only the ones you really need; most common case is hStdOutput.

If you want to communicate with the child process (through hStdInput), you need to wait for it to initialize by calling WaitForInputIdle.

这篇关于从另一个执行和捕获一个程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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