System()vs CreateProcess()vs ShellExecute()(System() vs CreateProcess() vs ShellExecute())

   IT问题网   2020-06-27 00:00:00

问 题

这里有一个适合所有人的,我在我的主要c ++程序中运行批处理文件。据我所知,批处理成为一个可能挂起主程序的子程序,直到它完成。现在我应该使用哪种方法,以便主程序在批处理时继续沿着它的快乐方式继续。主程序也可能会在第一个孩子运行时创建新的子实例!欢迎任何想法!这是windows。

解决方案

你想要一个建议:

1.使用 shellexecute 以异步行为从你的内部启动另一个程序。这可以是32或64可执行文件。

2.如果你想等待执行完成,你应该使用 shellexecuteex 设置标志 see_mask_nocloseprocess 因此您将获得一个有效的流程句柄,您可以等待 waitforsingleobject 。

3.你不能让你的程序等到执行结束,你可以通过 settimer 设置一个计时器,并检查你已启动的程序的就绪状态。

4.检查执行的错误状态总是一个好主意,也许是为了向用户显示出错(文件未找到,不是可执行文件等)。最简单的方法是显示 messagebox 。因此,您可以使用 formatmessage 函数来获取人类可读的错误文本。

问候并祝你好运。

标签:



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

将TCL代码转换为C ++ ...(Convert a TCL code to C++...)

problem for {set i 128} {$ilt;256} {incr i 1} { eval lut ...

如何从二进制文件中读取浮点值(How Read Float value from Binary File)

problem hi. i do want to read float value from binary fi ...

使用.bak文件还原数据库(Restore Database using.bak file)

problem good evening everybody, please say how to restor ...

在gridview中显示总和(Show sum In gridview)

problem my gridview has data which looks like below (for ...

Ajax客户端脚本错误(Ajax Client side script error)

problem if (typeof(sys) === #39;undefined#39; ...

如何在UP和DOWN键进行编码(How to code at the UP and DOWN key)

problem i want to move picture box up and down when a use ...

如何计算excel 2003中的时间平均值(how to calculate time averge in excel 2003)

problem hii to all. if any body knows how to calculateave ...

控制相关问题(Control related issue)

problem respected sir, i have a page in which i m gettin ...

在运行时动态绘制div(draw div dynamically at runtime)

problem hiii all, i have a page which i draw all its attr ...

转换数据库值(Convert a databse value)

problem i have a table one field is price and ...

如何使单元格的内容可见为false(How do i make the content of a cell visible false)

problem how do i make the content of a cell visible false ...

qtwebkit并连接cpp和javascript(qtwebkit and connect cpp and javascript)

problem hi to all i am using qwebkit i have a cpp object ...

response.flush&到Response.End(problem with response.flush & response.end)

problem hello everybody, i have used response.flush() wi ...

ShellExecute()不执行(ShellExecute() Not Executing)

problem i''m running a batch file from c++ code.when i ru ...

Radion Button使用Javascript隐藏/可见(Radion Button Hide/Visible Using Javascript)

problem i want hide/visible radio button using javascript ...

如何在此xml文件中插入/删除节点(how to insert/delete a node to this xml file)

problem hi all :) i search in webto find a code that ins ...

XML + DTD,不会出现在浏览器中(XML + DTD, won't show up in browser)

problem my code looks right, validates, but when i open i ...

什么是样品反射(What is Reflection with sample)

problem hi everybody, could u plz tell me reflection d ...

在封闭网络上获取设备的IP地址(optaining IP addresses of devices on a closed network)

problem i have a situation where i have multiple devices ...

如何限制用户在asp.net中通过javascript在TextBox中仅输入alphabates(How to Restrict user to enter only alphabates in TextBox by javascript in asp.net)

problem how to restrict user to enter onlyalphabates in t ...