delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/08/11/12:27:40

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
From: Barry Kelly <bkelly DOT ie AT gmail DOT com>
To: Cygwin Mailing List <cygwin AT cygwin DOT com>
Subject: PATCH: cygutils/cygstart - wait till task terminates (i.e. run in foreground)
Date: Mon, 11 Aug 2008 17:26:44 +0100
Message-ID: <40q0a4d1qej604aerns94mr6562dr5tigg@4ax.com>
X-Mailer: Forte Agent 4.2/32.1117
MIME-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

----=_42q0a4dsqt8oqqk7b48gpkninlklbaihf5.MFSBCHJLHS
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable

I find cygstart useful generally, but ShellExecute/Ex has more options
than cygstart exposes.

In particular, I'd like to be able to write a script that starts an
action and waits for it to complete, and then perform another action.
This means that I don't want cygstart to return until the process it has
started exits (modulo MDI etc).

ShellExecuteEx can return the process handle, which can then be waited
on.

I've written a patch against cygutils-1.3.2-1 that implements this
functionality via a new "-w | --wait" argument.

I've attached the patch for review. Is there any other place I should be
posting to submit this patch?

-- Barry

--=20
http://barrkel.blogspot.com/

----=_42q0a4dsqt8oqqk7b48gpkninlklbaihf5.MFSBCHJLHS
Content-Type: application/octet-stream; name=cygstart-1.3.2-1.bjk-wait.patch
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=cygstart-1.3.2-1.bjk-wait.patch

ZGlmZiAtciAtdTMgc3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q29uKTsKICAgICAgICAgICAgICAgICBmcmVl
KHByb2dyYW1fbmFtZSk7CiAgICAgICAgICAgICAgICAgaWYgKGFjdGlvbikK
QEAgLTMyNSw5ICszNDEsMTQgQEAKICAgICAgICAgICAgICAgICBzaG93ID0g
U1dfU0hPV05PUk1BTDsKICAgICAgICAgICAgICAgICBicmVhazsKIAorICAg
ICAgICAgICAgLyogU3RhcnR1cCBvcHRpb25zICovCisgICAgICAgICAgICBj
YXNlICd3JzoKKyAgICAgICAgICAgICAgICBzdGFydEZsYWdzIHw9IFNGX1dB
SVQ7CisgICAgICAgICAgICAgICAgYnJlYWs7CisKICAgICAgICAgICAgIC8q
IFRyb3VibGVzaG9vdGluZyBvcHRpb25zICovCiAgICAgICAgICAgICBjYXNl
ICdFJzoKLSAgICAgICAgICAgICAgICB2ZXJib3NlID0gMTsKKyAgICAgICAg
ICAgICAgICBzdGFydEZsYWdzIHw9IFNGX1ZFUkJPU0U7CiAgICAgICAgICAg
ICAgICAgYnJlYWs7CiAgICAgICAgIH0KICAgICB9CkBAIC0zNzYsNyArMzk3
LDcgQEAKICAgICB9CiAKICAgICAvKiBTdGFydCBpdCEgKi8KLSAgICByZXQg
PSBjeWdTdGFydChmaWxlLCBhY3Rpb24sIGFyZ3MsIHdvcmtEaXIsIHNob3cs
IHZlcmJvc2UpOworICAgIHJldCA9IGN5Z1N0YXJ0KGZpbGUsIGFjdGlvbiwg
YXJncywgd29ya0Rpciwgc2hvdywgc3RhcnRGbGFncyk7CiAKICAgICBwb3B0
RnJlZUNvbnRleHQob3B0Q29uKTsKICAgICBmcmVlKHByb2dyYW1fbmFtZSk7
CkBAIC0zOTQsNyArNDE1LDcgQEAKIAogLyogU3RhcnQgYSBwcm9ncmFtLCBv
ciBvcGVuIGEgZmlsZSBvciBVUkwsIHVzaW5nIEN5Z3dpbiBQT1NJWCBwYXRo
cyAqLwogc3RhdGljIGludCBjeWdTdGFydChjb25zdCBjaGFyICphUGF0aCwg
Y29uc3QgY2hhci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gICAgICB9IGVs
c2UgeworICAgICAgICAgICAgZnByaW50ZihzdGRlcnIsICJVbmFibGUgdG8g
c3RhcnQgJyVzJzogJXNcbiIsIGFQYXRoLCBzdGFydEVycm9yKHJldCkpOwor
ICAgICAgICAgICAgcmV0dXJuIEZBTFNFOworICAgICAgICB9CiAgICAgfSBl
bHNlIHsKLSAgICAgICAgcHJpbnRmKCJVbmFibGUgdG8gc3RhcnQgJyVzJzog
JXNcbiIsIGFQYXRoLCBzdGFydEVycm9yKHJldCkpOwotICAgICAgICByZXR1
cm4gRkFMU0U7CisgICAgICAgIFNIRUxMRVhFQ1VURUlORk8gc2VpOworICAg
ICAgICAKKyAgICAgICAgbWVtc2V0KCZzZWksIDAsIHNpemVvZihzZWkpKTsK
KyAgICAgICAgc2VpLmNiU2l6ZSA9IHNpemVvZihzZWkpOworICAgICAgICBz
ZWkubHBWZXJiID0gYWN0aW9uOworICAgICAgICBzZWkubHBGaWxlID0gYVBh
dGg7CisgICAgICAgIHNlaS5scFBhcmFtZXRlcnMgPSBhcmdzOworICAgICAg
ICBzZWkubHBEaXJlY3RvcnkgPSB3b3JrRGlyOworICAgICAgICBzZWkublNo
b3cgPSBzaG93OworICAgICAgICBzZWkuZk1hc2sgfD0gU0VFX01BU0tfTk9D
TE9TRVBST0NFU1MgfCBTRUVfTUFTS19GTEFHX05PX1VJOworICAgICAgICAK
KyAgICAgICAgaWYgKCFTaGVsbEV4ZWN1dGVFeCgmc2VpKSkgeworICAgICAg
ICAgICAgaWYgKCgoaW50KSBzZWkuaEluc3RBcHApIDwgMzIpIHsKKyAgICAg
ICAgICAgICAgICBmcHJpbnRmKHN0ZGVyciwgIlVuYWJsZSB0byBzdGFydCAn
JXMnOiAlc1xuIiwgYVBhdGgsIHN0YXJ0RXJyb3IoKGludCkgc2VpLmhJbnN0
QXBwKSk7CisgICAgICAgICAgICAgICAgcmV0dXJuIEZBTFNFOworICAgICAg
ICAgICAgfSBlbHNlIHsKKyAgICAgICAgICAgICAgICBmcHJpbnRmKHN0ZGVy
ciwgIlVuYWJsZSB0byBzdGFydCAnJXMnOiAiLCBhUGF0aCk7CisgICAgICAg
ICAgICAgICAgcHJpbnRMYXN0RXJyb3Ioc3RkZXJyKTsKKyAgICAgICAgICAg
ICAgICBmcHJpbnRmKHN0ZGVyciwgIlxuIik7CisgICAgICAgICAgICAgICAg
cmV0dXJuIEZBTFNFOworICAgICAgICAgICAgfQorICAgICAgICB9CisgICAg
ICAgIAorICAgICAgICBpZiAoc2VpLmhQcm9jZXNzKSB7CisgICAgICAgICAg
ICBXYWl0Rm9yU2luZ2xlT2JqZWN0KHNlaS5oUHJvY2VzcywgSU5GSU5JVEUp
OworICAgICAgICAgICAgQ2xvc2VIYW5kbGUoc2VpLmhQcm9jZXNzKTsKKyAg
ICAgICAgfQorICAgICAgICAKKyAgICAgICAgcmV0dXJuIFRSVUU7CisgICAg
fQorfQorCisvKiBQcmludCBhIGNvcnJlY3RseS1sb2NhbGl6ZWQgZXJyb3Ig
bWVzc2FnZSBmb3IgR2V0TGFzdEVycm9yKCkgdG8gdGhlIGdpdmVuIAorICAg
ZmlsZSBkZXNjcmlwdG9yLiAqLworc3RhdGljIHZvaWQgcHJpbnRMYXN0RXJy
b3IoRklMRSogZmlsZSkKK3sKKyAgICBMUFNUUiBidWYgPSAwOworICAgIAor
ICAgIGlmICghRm9ybWF0TWVzc2FnZSgKKyAgICAgICAgRk9STUFUX01FU1NB
R0VfQUxMT0NBVEVfQlVGRkVSIHwgRk9STUFUX01FU1NBR0VfRlJPTV9TWVNU
RU0sCisgICAgICAgIDAsCisgICAgICAgIEdldExhc3RFcnJvcigpLAorICAg
ICAgICAwLAorICAgICAgICAoTFBTVFIpICZidWYsCisgICAgICAgIDAsIC8v
IG1pbiBzaXplCisgICAgICAgIDApKQorICAgIHsKKyAgICAgICAgLy8gYXZv
aWQgcmVjdXJzaW9uIGdldHRpbmcgbWVzc2FnZSAtIHBvc3NpYmxlIGJ1dCBp
bmZpbml0ZS1wcm9uZQorICAgICAgICBmcHJpbnRmKGZpbGUsICJDb3VsZG4n
dCByZXRyaWV2ZSBlcnJvciBtZXNzYWdlIik7CisgICAgICAgIHJldHVybjsK
ICAgICB9CisgICAgCisgICAgZnB1dHMoYnVmLCBmaWxlKTsKKyAgICAKKyAg
ICBMb2NhbEZyZWUoYnVmKTsKIH0KIAogLyogUmV0dXJuIGFuIGVycm9yIG1l
c3NhZ2UsIGdpdmVuIGEgU2hlbGxFeGVjdXRlIHJldHVybiBjb2RlICovCg==


----=_42q0a4dsqt8oqqk7b48gpkninlklbaihf5.MFSBCHJLHS
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/
----=_42q0a4dsqt8oqqk7b48gpkninlklbaihf5.MFSBCHJLHS--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019