summaryrefslogtreecommitdiff
path: root/ghc/InstallShield
diff options
context:
space:
mode:
authorrrt <unknown>2001-06-22 13:32:45 +0000
committerrrt <unknown>2001-06-22 13:32:45 +0000
commitca2b5e30605e4113a3cb8bfe8349e336fabb97ff (patch)
tree6309949080958d1b24701f8949b6abfa5d1b274f /ghc/InstallShield
parentc9ed624be9c92be63178bded7ebabffd8136e9a6 (diff)
downloadhaskell-ca2b5e30605e4113a3cb8bfe8349e336fabb97ff.tar.gz
[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.
Diffstat (limited to 'ghc/InstallShield')
-rw-r--r--ghc/InstallShield/runexe.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/ghc/InstallShield/runexe.c b/ghc/InstallShield/runexe.c
index acdd5db989..e55845d0b4 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;
}