如何获取调用可执行文件的终止代码?
主要软件: LabWindows/CVI Development Systems>>LabWindows/CVI Full Development System
主要软件版本: 4.0.1
主要软件修正版本: N/A
次要软件: N/A
问题: 我怎样才能获得一个调用的EXE文件的终止代码? ANSI函数system()和CVI的LaunchExecutableEx函数都不能获得调用的EXE文件的终止代码。
解答: 下面是采用Window的SDK技术实现这个功能的一段代码:
#define WIN32_LEAN_AND_MEAN 1
#include "windows.h"
static char szCommand[] = "build.exe";
static STARTUPINFO si;
static PROCESS_INFORMATION piProcess;
static BOOL result;
static DWORD dwExitCode;
static int exitCode;
ZeroMemory(&si,sizeof si);
si.cb=sizeof si;
result=CreateProcess(NULL,szCommand,NULL,NULL,FALSE,
CREATE_DEFAULT_ERROR_MODE|DETACHED_PROCESS,
NULL,NULL,&si,&piProcess);
if (result==TRUE)
{
CloseHandle(piProcess.hThread);
if (WaitForSingleObject(piProcess.hProcess,INFINITE)!=WAIT_FAILED)
GetExitCodeProcess(piProcess.hProcess,&dwExitCode);
CloseHandle(piProcess.hProcess);
exitCode = dwExitCode;
}
相关链接:
附件:
报告日期: 10/17/2006
最近更新: 10/19/2006
文档编号: 161BHOTL
Other Support Options
Ask the NI Community
Collaborate with other users in our discussion forums
Request Support from an Engineer
A valid service agreement may be required, and support options vary by country.