X-Recipient: archive-cygwin@delorie.com
X-Spam-Check-By: sourceware.org
Date: Fri, 5 Sep 2008 00:05:41 +0100
From: Alex Smith <madalexonline@yahoo.co.uk>
To: cygwin@cygwin.com
Subject: PATCH: Re: cygutils/cygstart - wait till task terminates - also 	pass on exit status
Message-ID: <20080904230541.GA10174@router.inet>
Reply-To: madalexonline@yahoo.co.uk
References: <40q0a4d1qej604aerns94mr6562dr5tigg@4ax.com> <48A0AF77.30709@mscha.org>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="M9NhX3UHpAaciwkO"
Content-Disposition: inline
In-Reply-To: <48A0AF77.30709@mscha.org>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
Precedence: bulk
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie.com@cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

--M9NhX3UHpAaciwkO
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

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

--M9NhX3UHpAaciwkO
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="cygstart-1.3.2-1.aws-wait-return.patch"

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;
     }
 }
 


--M9NhX3UHpAaciwkO
Content-Type: text/plain; charset=us-ascii

--
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/
--M9NhX3UHpAaciwkO--
