Commit ca2b5e30 authored by rrt's avatar rrt
Browse files

[project @ 2001-06-22 13:32:45 by rrt]

Add some extra tests and correct some error messages. This file is no longer
used for its original purpose, but is a useful example of how to start and
manage processes under Windows.
parent c9ed624b
......@@ -4,7 +4,7 @@
const char *prog = "runexe";
#define BUFLEN 1025
#define BUFLEN 65537
void die(char *fmt, ...)
{
......@@ -26,12 +26,13 @@ void warn(char *fmt, ...)
fprintf(stderr, "\n");
va_end(ap);
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
{
STARTUPINFO sInfo;
PROCESS_INFORMATION pInfo;
TCHAR buf[BUFLEN];
DWORD retCode;
sInfo.cb = sizeof(STARTUPINFO);
sInfo.lpReserved = NULL;
......@@ -41,10 +42,18 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmd
sInfo.lpTitle = NULL;
sInfo.dwFlags = 0;
if (GetCurrentDirectory(BUFLEN, buf) == 0) die("no parameters given");
if (strlen(lpszCmdParam) == 0) warn("couldn't get current directory");
if (GetCurrentDirectory(BUFLEN, buf) == 0) die("couldn't get current directory");
if (strlen(lpszCmdParam) == 0) die("no parameters given");
warn("cwd: %s\n", buf);
warn("runexing >>>%s<<<\n", lpszCmdParam);
CreateProcess(NULL, lpszCmdParam, NULL, NULL, FALSE, 0, NULL, NULL, &sInfo, &pInfo);
return 0;
if (!CreateProcess(NULL, lpszCmdParam, NULL, NULL, FALSE, 0, NULL, NULL, &sInfo, &pInfo))
die("could not create process");
WaitForSingleObject(pInfo.hProcess, INFINITE);
if (GetExitCodeProcess(pInfo.hProcess, &retCode) == 0) retCode = -1;
CloseHandle(pInfo.hProcess);
CloseHandle(pInfo.hThread);
printf("return code %ld\n", retCode);
return retCode;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment