+2008-09-04 Alex Smith <madalexonline@yahoo.co.uk>
+
+ If cygstart -w, then propagate child exit status.
+ * src/cygstart/cygstart.c (main): exit with
+ value returned by cygStart().
+ (cygStart): If -w/--wait, then get exit status
+ of child process and return it.
+
2008-08-10 Barry Kelly <bkelly.ie@gmail.com>
+ Add -w/--wait option to cygstart.
* src/cygstart/cygstart.c: New enum StartFlags.
(main): Add startup options category, containing
new -w/--wait option. Use it to set StartFlags.
"for the first time", NULL},
{ NULL, '\0', 0, NULL, 0, NULL, NULL }
};
-
+
/* Startup options */
struct poptOption startupOptionsTable[] = {
{ "wait", 'w', POPT_ARG_NONE, NULL, 'w',
if (file)
free(file);
- return (ret ? 0 : 1);
+ return ret;
}
/* Start a program, or open a file or URL, using Cygwin POSIX paths */
printf("ShellExecute(NULL, \"%s\", \"%s\", \"%s\", \"%s\", %d)\n",
action, aPath, args, workDir, show);
}
-
+
if (!(startFlags & SF_WAIT)) {
int ret = (int) ShellExecute(NULL, action, aPath, args, workDir, show);
-
+
if (ret >= 32) {
- return TRUE;
+ return 0;
} else {
fprintf(stderr, "Unable to start '%s': %s\n", aPath, startError(ret));
- return FALSE;
+ return 1;
}
} else {
SHELLEXECUTEINFO sei;
-
+
memset(&sei, 0, sizeof(sei));
sei.cbSize = sizeof(sei);
sei.lpVerb = action;
sei.lpDirectory = workDir;
sei.nShow = show;
sei.fMask |= SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
-
+
if (!ShellExecuteEx(&sei)) {
if (((int) sei.hInstApp) < 32) {
fprintf(stderr, "Unable to start '%s': %s\n", aPath, startError((int) sei.hInstApp));
- return FALSE;
+ return 1;
} else {
fprintf(stderr, "Unable to start '%s': ", aPath);
printLastError(stderr);
fprintf(stderr, "\n");
- return FALSE;
+ return 1;
}
}
-
+
if (sei.hProcess) {
+ DWORD code;
WaitForSingleObject(sei.hProcess, INFINITE);
+ if (!GetExitCodeProcess(sei.hProcess, &code)) {
+ code = 1;
+ }
CloseHandle(sei.hProcess);
+ return (int) code;
}
-
- return TRUE;
+
+ return 0;
}
}
static void printLastError(FILE* file)
{
LPSTR buf = 0;
-
+
if (!FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
0,
fprintf(file, "Couldn't retrieve error message");
return;
}
-
+
fputs(buf, file);
-
+
LocalFree(buf);
}
{
printTopDescription(f, name);
printLicense(f, name);
-}
+}