c++ 调用外部程序exe-ShellExecuteEx
2015-06-02 10:29
513 查看
此方法最实用的调用exe.
#include <ShellAPI.h>
传给控制台程序参数
#include <ShellAPI.h>
string file_path = s_run_dir+"\\ConsoleApplication1.exe"; if (!myfile.IsFileExist(file_path)) { return 1; } LPCWSTR lp_file_path = mystring.StringToLPCWSTR(file_path); SHELLEXECUTEINFO ShExecInfo; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = NULL; ShExecInfo.lpFile = lp_file_path; ShExecInfo.lpParameters = __T("D:\\a.txt D:\\b.txt D:\\c.txt");//传出去的参数 ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_SHOW; ShExecInfo.hInstApp = NULL; BOOL b_ret=ShellExecuteEx(&ShExecInfo); if (b_ret) { //等待调用启动的exe关闭,此处要设置成ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; WaitForSingleObject(ShExecInfo.hProcess, INFINITE); } else { return 2; }
传给控制台程序参数
#include "stdafx.h" #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { // 参数个数,第一个参数为可执行文件路径 int iParamCount = argc; cout << "参数个数:" << iParamCount << endl; for (int i = 0; i < iParamCount; i++) { cout << endl << "第" << i + 1 << "个参数:"; wprintf(argv[i]); } getchar(); return 0; }
相关文章推荐
- 在PowerShell 5.0中用Class关键字定义方法
- 在opensuse13.2上安装powerline来使bash变得漂亮
- PowerShell在控制台输出特殊符号的方法
- bash之条件判断语句及循环语句
- 06 Linux下Shell介绍
- PowerShell实现查询打开某个文件的默认应用程序
- 生产环境上shell的解读
- PowerShell实现在字符串中查找大写字母
- PowerShell实现在控制台中插入绿色的打勾符号
- 8个实用的Shell脚本分享
- Shell脚本编程的常识
- Linux Shell脚本攻略(1.11)
- linux xshell的图形化支持
- SSH Secure Shell Client中文乱码的解决办法
- 设置git bash打印log的颜色
- shell
- HBase 常用Shell命令
- Hbase shell 常用命令
- linux程序设计——shell程序设计(第二章)
- 初学Linux--shell