X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2FInstallShield%2Frunexe.c;h=c1becfbcaa7db5ce5b71641e27cf6a7829c64980;hb=90af5e7b48c2f0ec74891c1399d46781d078484a;hp=c01f0b187d85ca16550e3aac8ce84b6f7657eda2;hpb=8162c20d42283c360308a46374b9307b3530ec08;p=ghc-hetmet.git diff --git a/ghc/InstallShield/runexe.c b/ghc/InstallShield/runexe.c index c01f0b1..c1becfb 100644 --- a/ghc/InstallShield/runexe.c +++ b/ghc/InstallShield/runexe.c @@ -1,11 +1,38 @@ +#include +#include #include const char *prog = "runexe"; +#define BUFLEN 65537 + +void die(char *fmt, ...) +{ + va_list ap = va_start(ap, fmt); + + fprintf(stderr, "%s: ", prog); + vfprintf(stderr, fmt, ap); + fprintf(stderr, "\n"); + va_end(ap); + exit(1); +} + +void warn(char *fmt, ...) +{ + va_list ap = va_start(ap, fmt); + + fprintf(stderr, "%s: ", prog); + vfprintf(stderr, fmt, ap); + 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; @@ -14,11 +41,19 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmd sInfo.lpDesktop = NULL; sInfo.lpTitle = NULL; sInfo.dwFlags = 0; - - if (strlen(lpszCmdParam) == 0) { - printf("%s: no parameters given\n", prog); - exit(1); - } - CreateProcess(NULL, lpszCmdParam, NULL, NULL, FALSE, 0, NULL, NULL, &sInfo, &pInfo); - return 0; + + 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); + if (!CreateProcess(NULL, lpszCmdParam, NULL, NULL, TRUE, 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; }