public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Cygwin convert environment paths
@ 2020-05-10 12:42 Steven Penny
  2020-05-10 15:06 ` Achim Gratz
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Steven Penny @ 2020-05-10 12:42 UTC (permalink / raw)
  To: cygwin

I see here:

<https://cygwin.com/cygwin-ug-net/setup-env.html>

That Cygwin does convert some environment variables, from Windows format to
Unix format. For example HOME and TMP. But for me at least, are some important
omissions.

I use APPDATA and PROGRAMFILES a good amount, and those arent converted. To make
it worse, HOMEDRIVE and SYSTEMDRIVE arent converted either, meaning you cant
manually construct the path starting with a variable. This causes some
problems. Take this example:

    <?php
    $s_old = realpath('a.txt');
    $s_new = getenv('HOMEDRIVE') . DIRECTORY_SEPARATOR . 'a.txt';
    # PHP Warning:  symlink(): No such file or directory
    symlink($s_old, $s_new);

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Cygwin convert environment paths
  2020-05-10 12:42 Cygwin convert environment paths Steven Penny
@ 2020-05-10 15:06 ` Achim Gratz
  2020-05-10 17:52 ` Doug Henderson
  2020-05-12 19:18 ` Andrey Repin
  2 siblings, 0 replies; 7+ messages in thread
From: Achim Gratz @ 2020-05-10 15:06 UTC (permalink / raw)
  To: cygwin

Steven Penny via Cygwin writes:
> I use APPDATA and PROGRAMFILES a good amount, and those arent converted. To make
> it worse, HOMEDRIVE and SYSTEMDRIVE arent converted either, meaning you cant
> manually construct the path starting with a variable.

That's what cygpath is there for, among other things.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Waldorf MIDI Implementation & additional documentation:
http://Synth.Stromeko.net/Downloads.html#WaldorfDocs

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Cygwin convert environment paths
  2020-05-10 12:42 Cygwin convert environment paths Steven Penny
  2020-05-10 15:06 ` Achim Gratz
@ 2020-05-10 17:52 ` Doug Henderson
  2020-05-12 19:18 ` Andrey Repin
  2 siblings, 0 replies; 7+ messages in thread
From: Doug Henderson @ 2020-05-10 17:52 UTC (permalink / raw)
  To: cygwin

On Sun, 10 May 2020 at 06:46, Steven Penny via Cygwin <> wrote:

> <snip>
> That Cygwin does convert some environment variables, from Windows format to
> Unix format. For example HOME and TMP. But for me at least, are some
> important
> omissions.
>
<snip>
>

In general, converting environment variable owned by Windows to cygwin
format is a very bad idea. These are the variables that are present in
cmd.exe in a vanilla Windows install. The only exception is the PATH
variable.

Personally, I always set CYGWIN_NOWINPATH=1 in the system environment
variables to avoid accidentally calling a windows program while in cygwin.
Every time I want to call a windows program from cygwin, I explicitly use
its full path. Or I have create and use a shell alias that contains that
full path.

There is no problem with HOME and TMP  (and a few others like TEMP,
BROWSER, EDITOR, INFOPATH, PWD, SHELL), because these are not normally set
in the Windows environment, or during the execution of cmd.exe. (I can't
comment on powershell, as I don't use it.)

I experimented with using cygpath to pre-convert several variables that
have windows paths, or windows path lists in order to interchangeably run
the cygwin version and a windows version of the same application, and to
spawn windows programs from cygwin programs and cygwin programs from
windows programs. I failed to create an environment that worked for both
types of programs at the same time.

What I found to partially work for interchangeability was to wrap the
cygwin program in a bash script to perform environment conversions, This
failed, though, when the cygwin program spawned a windows program which, of
course, expected windows paths and path lists in its environment. I also
tried wrapping the windows programs with similar conversion,

An alternate approach, that worked for my own cygwin code was to create
variables like CYG_HOMEDRIVE, or WIN_HOME. But this introduces a different
set of problems.

I also tried a couple of mingw64 installations: the standard one, and the
one packaged with Git for Windows. Programs from those projects tended to
work in the windows environment, but allowed you to use linux style file
names directly.

I did not try mixing cygwin and mingg64 programs.

My conclusion was that there is no universal way to make unmodified
programs work in the alternate environment.

In the OP's specific case of using HOMEDRIVE, he must accept that this is a
variable "owned" by windows, and thus not found in the linux environment.
Any code that is meant to execute in both cygwin and linux must have code
paths for each. And a cygwin program that wants to use a Windows variable,
must perform its own conversions, either manually or using cygpath. As I
understand it, the cygpath program is a thin wrapper over a library call,
so a CFFI (C Foreign Function Interface) might work.

HTH
Doug

-- 
Doug Henderson, Calgary, Alberta, Canada - from gmail.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Cygwin convert environment paths
  2020-05-10 12:42 Cygwin convert environment paths Steven Penny
  2020-05-10 15:06 ` Achim Gratz
  2020-05-10 17:52 ` Doug Henderson
@ 2020-05-12 19:18 ` Andrey Repin
  2 siblings, 0 replies; 7+ messages in thread
From: Andrey Repin @ 2020-05-12 19:18 UTC (permalink / raw)
  To: Steven Penny, cygwin

Greetings, Steven Penny!

> I see here:

> <https://cygwin.com/cygwin-ug-net/setup-env.html>

> That Cygwin does convert some environment variables, from Windows format to
> Unix format. For example HOME and TMP. But for me at least, are some important
> omissions.

> I use APPDATA and PROGRAMFILES a good amount, and those arent converted. To make
> it worse, HOMEDRIVE and SYSTEMDRIVE arent converted either, meaning you cant
> manually construct the path starting with a variable. This causes some
> problems. Take this example:

These are not making any sense for Cygwin itself, so they are left alone.

>     <?php
>     $s_old = realpath('a.txt');
>     $s_new = getenv('HOMEDRIVE') . DIRECTORY_SEPARATOR . 'a.txt';
>     # PHP Warning:  symlink(): No such file or directory
>     symlink($s_old, $s_new);

Use native php ?…


-- 
With best regards,
Andrey Repin
Tuesday, May 12, 2020 22:17:30

Sorry for my terrible english...

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Cygwin convert environment paths
  2020-05-10 15:48 Steven Penny
  2020-05-10 16:41 ` Marco Atzeri
@ 2020-05-10 19:05 ` Achim Gratz
  1 sibling, 0 replies; 7+ messages in thread
From: Achim Gratz @ 2020-05-10 19:05 UTC (permalink / raw)
  To: cygwin

Steven Penny via Cygwin writes:
>> That's what cygpath is there for, among other things.
>
> You expect people to use cygpath... from within PHP?

These are neither POSIX or Cygwin variables, so yes, if you expect to
use them from Cygwin PHP you either need to explicitly deal with the
fact that these are Windows environment variables or convert them
(preferrably not under the same name) to Cygwin environment variables
before starting PHP.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

SD adaptation for Waldorf rackAttack V1.04R1:
http://Synth.Stromeko.net/Downloads.html#WaldorfSDada

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Cygwin convert environment paths
  2020-05-10 15:48 Steven Penny
@ 2020-05-10 16:41 ` Marco Atzeri
  2020-05-10 19:05 ` Achim Gratz
  1 sibling, 0 replies; 7+ messages in thread
From: Marco Atzeri @ 2020-05-10 16:41 UTC (permalink / raw)
  To: cygwin

Am 10.05.2020 um 17:48 schrieb Steven Penny via Cygwin:
>> That's what cygpath is there for, among other things.
> 
> You expect people to use cygpath... from within PHP?

we expect they can use cygpath to set a cygwin equivalent
variable in their own scripts or boot shell scripts

$ CYG_HOMEDRIVE=$(cygpath ${HOMEDRIVE})
$ echo $CYG_HOMEDRIVE
/cygdrive/c

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Cygwin convert environment paths
@ 2020-05-10 15:48 Steven Penny
  2020-05-10 16:41 ` Marco Atzeri
  2020-05-10 19:05 ` Achim Gratz
  0 siblings, 2 replies; 7+ messages in thread
From: Steven Penny @ 2020-05-10 15:48 UTC (permalink / raw)
  To: Stromeko; +Cc: cygwin

> That's what cygpath is there for, among other things.

You expect people to use cygpath... from within PHP?

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-05-12 19:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-10 12:42 Cygwin convert environment paths Steven Penny
2020-05-10 15:06 ` Achim Gratz
2020-05-10 17:52 ` Doug Henderson
2020-05-12 19:18 ` Andrey Repin
2020-05-10 15:48 Steven Penny
2020-05-10 16:41 ` Marco Atzeri
2020-05-10 19:05 ` Achim Gratz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).