PATCH: Re: cygutils/cygstart - wait till task terminates - also pass on exit status

Alex Smith madalexonline@yahoo.co.uk
Thu Sep 4 23:06:00 GMT 2008


The recent patch sumbitted by Barry Kelly to add an option to cygstart
to have it wait for the process to terminate is most useful. However it
would be more useful still if it were to return the exit status of the
process in this case.

The attached patch implements this small addition and should be applied
on top of Barry Kelly's.

- Alex
-------------- next part --------------
diff -r -u -p src/cygstart/cygstart.c newsrc/cygstart/cygstart.c
--- src/cygstart/cygstart.c	2008-09-04 22:49:41.000000000 +0100
+++ newsrc/cygstart/cygstart.c	2008-09-04 23:04:52.000000000 +0100
@@ -410,7 +410,7 @@
     if (file)
         free(file);
 
-    return (ret ? 0 : 1);
+    return ret;
 }
 
 /* Start a program, or open a file or URL, using Cygwin POSIX paths */
@@ -454,10 +454,10 @@
         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;
@@ -474,21 +474,26 @@
         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;
     }
 }
 

-------------- next part --------------
--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


More information about the Cygwin mailing list