delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2016/08/09/20:50:35

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:from:reply-to:message-id:to:subject
:in-reply-to:references:mime-version:content-type
:content-transfer-encoding; q=dns; s=default; b=jAaj7ZBRzqlSETQF
RBvlFfz2YMM74xPLxT5vbRyXXCGJTzufh/8Ewqohs6c62GSidrHdrg4fbSCF0fmn
EpC/d00Ieiv9BBthNM7MTxMN9MxGHVgZCQoFIse/RJCfSDp4q/Iqn3r77l79Wh+C
a7F+h/pOfacFRCrNZiHnG09uroo=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:from:reply-to:message-id:to:subject
:in-reply-to:references:mime-version:content-type
:content-transfer-encoding; s=default; bh=YMy+1Az42wvvd8T24obIDf
jSZFc=; b=mjKy6QjC3S64WG99GqlCIRR0yaUGqdojugIPNNDzOpg0lRyNn3UgGR
5DqGwaUVfRl8yaLlne/xqiFANaRXvk/oRCSMC/m5zkiLCBWdsdfqU21UiEU94Sn/
GUa4cIjnWAjb6G+tI9gAzrN8okQuD4jinvgqOPf/lV5owCkNuTftk=
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
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=2.0 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,KAM_THEBAT,MIME_BASE64_BLANKS,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2 spammy=men, H*F:D*yandex.ru, H*UA:Bat!, H*x:Bat!
X-HELO: forward17p.cmail.yandex.net
Authentication-Results: smtp2p.mail.yandex.net; dkim=pass header.i=@yandex.ru
X-Yandex-Suid-Status: 1 0
Date: Wed, 10 Aug 2016 03:44:46 +0300
From: Andrey Repin <anrdaemon AT yandex DOT ru>
Reply-To: cygwin AT cygwin DOT com
Message-ID: <769354915.20160810034446@yandex.ru>
To: Corinna Vinschen <cygwin AT cygwin DOT com>, cygwin AT cygwin DOT com
Subject: Re: PATHEXT is fundamental to Windows and Should be recognised by CYGWIN
In-Reply-To: <20160808143321.GS25811@calimero.vinschen.de>
References: <001001d1edf1$a4e1ae90$eea50bb0$@rogers.com> <1C0AE95E-0118-4353-AA77-4D41F1AE9AE1 AT solidrocksystems DOT com> <001a01d1eea9$f7949a90$e6bdcfb0$@rogers.com> <76ec05e9-140a-19cb-942b-698582c3d024 AT gmail DOT com> <001f01d1ef2c$f04af9e0$d0e0eda0$@rogers.com> <20160805152951 DOT GO25811 AT calimero DOT vinschen DOT de> <57A6ED1C DOT 1060402 AT gmx DOT de> <20160808112321 DOT GF32150 AT calimero DOT vinschen DOT de> <e90174df-61b4-17c8-064b-30009e6ad559 AT gmail DOT com> <20160808143321 DOT GS25811 AT calimero DOT vinschen DOT de>
MIME-Version: 1.0
X-IsSubscribed: yes
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id u7A0oUkm028410

Greetings, Corinna Vinschen!

>> As for PATHEXT we can do the following scenario instead.
>> 
>> export PATHEXT="$PATHEXT;.TXT"
>> vi foo.txt
>> :set ff=dos
>> i
>> a
>> b
>> c
>> <ESC>
>> :wq
>> cmd /c foo

> As you show here, the PATHEXT definition is so that it also contains
> file suffixes which require to know the interpreters starting them.  To
> implement that, the lib would have to either read the registry to know
> the connection between suffix and interpreter (which is pretty
> convoluted), or it would have to "start the file", aka call ShellExecute
> on the file, without knowing what process will come up as child process.
> In your example that would be Notepad or Write.

> The way this works is just not feasible to be used from inside the DLL,
> e.g.:

> - ShellExecute does not return a handle to the called process, so the
>   parent can't wait(2) for it.

ShellExecuteEx does, but it will not help you a single bit.

> - ShellExecute does not allow to specify an environment for the child
>   process.  Cygwin's Windows environment is reduced to minimal size.
>   Cygwin children inherit the POSIX environment by a simple copy
>   process.  Only when starting a non-Cygwin process, this process gets
>   a full Windows environment by means of the matching CreateProcess
>   parameter.

ShellExecuteEx does, but…

> So, if we actually implement PATHEXT, its usage would be limited to
> suffixes of binary files and files starting with #!<interpreter>, or we
> would have to use a way to start an application which doesn't work well
> in a POSIX scenario, or we would have to search the registry for the
> suffix linkage.  Additionally to searching a variable number of files
> for each single file access.

> Additionally I would (again?) like to stress that PATHEXT is a feature
> of CMD, aka, the shell.  It's not a feature of the underlying libs.

Add to that, ShellExecute(Ex) can't bind to the current console.
Even if the starting program is a console app, it will, always, create a new
console.
Alternative is to manually parse registry, like CMD apparently does, and
directly find the app to execute.
It's not very convoluted. Thankfully THIS part of Windows is fairly
straightforward and - for the present task - well-documented.
All you have to do is

1. lookup the name of the associated "handler" for a given ".ext"... In two
places... (user registry first, then system);
2. for the given "handler" key, lookup its default "action" value;
(often "open", but not always; many, so many implementors stupidly assume that
"open" is always the default action, while documentation explicitly states
that if you just want to call default action, don't pass any action at all!
And so they call ShellExecuteEx, like white men, but then defeat all their
good by passing an explicit "open" to it...)
3. for the found "action" value lookup two values:
  a) "handler"/"action"/shell/command/@ - command to execute;
  b) "handler"/"action"/shell/command/Path - additional search path;
4. If Path value exists, it should be prepended to the system's %PATH% for
about to be spawned process;
5. If command line contains "%1", it should be substituted by the script name
(if not, the script name simply appended to the end of exec line);
6. If command line contains "%*", it should be replaced by the "executing"
script arguments, as passed;
7. Finally, the constructed abomination should be executed.

Frankly, I've long since wanted to have ability to directly "execute" some of
the foreign scripts from Cygwin terminal.
If something like PATHEXT is implemented, I'd rather like to see it as the way
to bridge Cygwin to the native execution options, rather than to confuse
everyone by executing files at random.


-- 
With best regards,
Andrey Repin
Wednesday, August 10, 2016 03:04:53

Sorry for my terrible english...

- Raw text -


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