VC启动一个程序并等待运行结束

在VC插件里执行了ARM ADS的编译指令armlink和fromelf.

大致这样的

WinExec("armlink .....", SW_HIDE);

WinExec("fromelf .....", SW_HIDE);

因为fromelf要用到armlink的输出文件,但不运行正确,一起跑提示fromelf找不到armlink输出的那个文件。

看来WinExec()是异步执行armlink等命令了。肯定是创建进程去运行的,但是WinExec没有等待子进程退出就返回了.

试过WinExec("armlink ....   && fromelf ....", SW_HIDE);但是最终还是要用C访问fromelf的生成的文件。

所以只能用CreateProcess()了

 

PROCESS_INFORMATION ProcessInfo;

STARTUPINFO StartupInfo; //入口参数

ZeroMemory(&StartupInfo, sizeof(StartupInfo));

StartupInfo.cb = sizeof StartupInfo ; //分配大小

if(CreateProcess("armlink", NULL,

NULL,NULL,FALSE,0,NULL,

NULL,&StartupInfo,&ProcessInfo))

{

WaitForSingleObject(ProcessInfo.hProcess,INFINITE);

CloseHandle(ProcessInfo.hThread);

CloseHandle(ProcessInfo.hProcess);

}

 

后来查到也可以用ShellExecuteEx()

 

SHELLEXECUTEINFO ShExecInfo = {0};

ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);

ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;

ShExecInfo.hwnd = NULL;

ShExecInfo.lpVerb = NULL;

ShExecInfo.lpFile = "armlink";

ShExecInfo.lpParameters = "。。。。。";

ShExecInfo.lpDirectory = NULL;

ShExecInfo.nShow = SW_HIDE;

ShExecInfo.hInstApp = NULL;

ShellExecuteEx(&ShExecInfo);

WaitForSingleObject(ShExecInfo.hProcess,INFINITE);

你可能感兴趣的:(VC启动一个程序并等待运行结束)