This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATHEXT is fundamental to Windows and Should be recognised by CYGWIN


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...

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]