On Jan 27 09:08, john daintree via Cygwin wrote:
> Hi Audrey.
> 
> Here's an example of what's going on:
> 
> >>: export TMPDIR=/cygdrive/c/tmp/jd
> >>: export TMPDIR2=/cygdrive/c/tmp/jd2
> >>: cmd.exe
> Microsoft Windows [Version 10.0.22621.1105]
> (c) Microsoft Corporation. All rights reserved.
> 
> C:\>echo %TMPDIR%
> C:\tmp\jd
> 
> C:\>echo %TMPDIR2%
> /cygdrive/c/tmp/jd2
> 
> So, if I set TMPDIR and TMPDIR2 in bash, and then call cmd.exe then TMPDIR
> is changed to c:\tmp\jd but TMPDIR2 is left as /cygdrive/c/tmp/jd2
> 
> I was hoping that there's something I can do to get the following in
> cmd.exe:
> 
> C:\>echo %TMPDIR2%
> C:\tmp\jd2                                              # TMPDIR2 "mapped"
> to c:\.... in the same way that TMPDIR is
> 
> I hope that's a clearer example.
> 
> Note that the actual use case is calling other Win32 programs, and the
> environment variable name is different, but the above example is an attempt
> to simplify the repro.
> $PATH is mapped in  a similar way. So I assume that there is a list of names
> which are mapped. I'd like to be able to add my own names to that list.

Easy: Don't call the affected Win32 executable directly.  Call it
through a child process.

Two scenarios:

- Starting the nativ executable from a shell or a Makefile:

  Create a wrapper script which calls

    TMPDIR2="$(cygpath -wa ${TMPDIR2})
      
  before calling your native app.

- Starting the nativ executable from your own process:

  After fork(), call

    const char *tmpdir2_old;
    char *tmpdir2_new;

    tmpdir2_old = getenv ("TMPDIR2");
    tmpdir2_new = (char *) cygwin_create_path (CCP_POSIX_TO_WIN_A,
                                               tmpdir2_old);
    setenv ("TMPDIR2", tmpdir2_new, 1);
    free (tmpdir2_new);

  Then call execve or friends.  Alternatively you can construct the
  new environment like the above for any exec call taking an
  environment as argument, i.e, execve, execle, execvpe.


Corinna

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to