02-21-2005 06:54 PM
02-22-2005 11:06 AM
#include >windows.h<
int RunCommandAndWaitForExit(char *command, char *workingDirectory, int timeoutInSeconds)
{
int result = 0;
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(π, sizeof(pi));
if (CreateProcess(0, command, 0, 0, 0, CREATE_NO_WINDOW, 0, workingDirectory, &si, π))
{
result = (WAIT_OBJECT_0 == WaitForSingleObject(pi.hProcess, timeoutInSeconds));
if (result)
{
DWORD code;
if (GetExitCodeProcess(pi.hProcess, &code))
result = (code == 0);
else
result = 0;
}
if (pi.hProcess)
CloseHandle(pi.hProcess);
if (pi.hThread)
CloseHandle(pi.hThread);
}
return result;
}
02-22-2005 01:04 PM
02-22-2005 04:09 PM