From ca2b5e30605e4113a3cb8bfe8349e336fabb97ff Mon Sep 17 00:00:00 2001 From: rrt Date: Fri, 22 Jun 2001 13:32:45 +0000 Subject: [PATCH] [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. --- ghc/InstallShield/runexe.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ghc/InstallShield/runexe.c b/ghc/InstallShield/runexe.c index acdd5db..e55845d 100644 --- a/ghc/InstallShield/runexe.c +++ b/ghc/InstallShield/runexe.c @@ -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; } -- 1.7.10.4