5 const char *prog = "runexe";
9 void die(char *fmt, ...)
11 va_list ap = va_start(ap, fmt);
13 fprintf(stderr, "%s: ", prog);
14 vfprintf(stderr, fmt, ap);
15 fprintf(stderr, "\n");
20 void warn(char *fmt, ...)
22 va_list ap = va_start(ap, fmt);
24 fprintf(stderr, "%s: ", prog);
25 vfprintf(stderr, fmt, ap);
26 fprintf(stderr, "\n");
30 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
33 PROCESS_INFORMATION pInfo;
37 sInfo.cb = sizeof(STARTUPINFO);
38 sInfo.lpReserved = NULL;
39 sInfo.lpReserved2 = NULL;
40 sInfo.cbReserved2 = 0;
41 sInfo.lpDesktop = NULL;
45 if (GetCurrentDirectory(BUFLEN, buf) == 0) die("couldn't get current directory");
46 if (strlen(lpszCmdParam) == 0) die("no parameters given");
47 warn("cwd: %s\n", buf);
48 warn("runexing >>>%s<<<\n", lpszCmdParam);
49 if (!CreateProcess(NULL, lpszCmdParam, NULL, NULL, TRUE, 0, NULL, NULL, &sInfo, &pInfo))
50 die("could not create process");
52 WaitForSingleObject(pInfo.hProcess, INFINITE);
53 if (GetExitCodeProcess(pInfo.hProcess, &retCode) == 0) retCode = -1;
54 CloseHandle(pInfo.hProcess);
55 CloseHandle(pInfo.hThread);
56 printf("return code %ld\n", retCode);