System()vs CreateProcess()vs ShellExecute() [英] System() vs CreateProcess() vs ShellExecute()

查看:100
本文介绍了System()vs CreateProcess()vs ShellExecute()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,每个人都可以使用,我正在主c ++程序中运行一个批处理文件.据我了解,该批处理成为一个孩子,可能会挂断主程序,直到完成为止.现在,我应该使用哪种方法,该方法将允许主程序在批处理过程中沿其快乐的方式继续进行.同样,主程序可能并且可能会在第一个孩子正在运行时创建新的孩子实例!欢迎任何想法!这是Windows.

Here''s one for everyone, I''m running a batch file within my main c++ program. From what I understand is that the batch becomes a child that might hangup the main program untill it completes. Now which method should I use that would allow the main program to continue along it''s merry way while the batch is processing. Also the main program might and probably will create new child instances while the first child is running! Any thoughts welcome! This is Windows.

推荐答案

好,你想要一个建议:
1.使用ShellExecute以异步行为从您的内部启动另一个程序.这可以是32或64可执行文件.
2.如果要等待执行完成,则应使用ShellExecuteEx设置标志SEE_MASK_NOCLOSEPROCESS,这样您将获得可以使用WaitForSingleObject等待的有效进程句柄. 3.您一定不能让程序等待执行完毕,可以通过SetTimer设置计时器并检查已启动程序的就绪状态.
4.检查执行的错误状态总是一个好主意,也许是向用户显示出了什么问题(找不到文件,不是可执行文件,等等).最简单的方法是显示MessageBox.因此,您可以使用FormatMessage函数来获取人类可读的错误文本.
祝您好运.
Ok you want a suggestion:
1. Use ShellExecute to start another program from inside yours with asynchronous behauviour. This can be a 32- or 64- executable.
2. If you want to wait for the execution is finished, you should use ShellExecuteEx set the flag SEE_MASK_NOCLOSEPROCESS so you will get a valid process handle you can wait for with WaitForSingleObject.
3. You must not let your program wait until execution is finnished, you can set a timer by SetTimer and examine the ready state of the program youve started.
4. Its always a good idea to check the error state of the execution, perhaps to show the user whats going wrong (file not found, not an executable and so on). Simplest way is to display a MessageBox. Therefore you can use the FormatMessage function to obtain a human readable error text.
Regards and good luck.


这篇关于System()vs CreateProcess()vs ShellExecute()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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