Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#1572 TEMP env var is corrupted when running external app

MSYS
pending
Cesar Strauss
None
Bug
rejected
Unknown
False
2013-02-08
2011-08-14
Orgad Shaneh
No

On my machine, TEMP environment variable is defined as 'D:\Temp'.

When I run msys, 'echo $TEMP' gives '/tmp', and 'msysmnt' shows that D:\Temp is mounted on /tmp. That's fine.

When I run an external application from msys, the TEMP variable is modified to 'D:/Temp'.

To reproduce: Run msys, from it, run cmd /c "echo %TEMP%"

Discussion

<< < 1 2 3 4 5 > >> (Page 4 of 5)
  • Orgad Shaneh
    Orgad Shaneh
    2012-03-14

    ?

     
  • Cesar Strauss
    Cesar Strauss
    2012-03-16

    Sorry, your patch doesn't work for me. After applying it, I still get:

    $ cmd /c "echo %TEMP%"
    C:/Users/cstrauss/AppData/Local/Temp

    Earlier, I intended to investigate this further, but ran out of time.

     
  • Orgad Shaneh
    Orgad Shaneh
    2012-05-16

    Ok, that's really strange. Running cmd /c "echo %TEMP%" indeed prints it with forward slashes, but replacing cmd with cmd.exe does print it with native slashes (with my patch).

    Tried with ActivePerl, it prints forward slashes.

    Any ideas?

     
  • Orgad Shaneh
    Orgad Shaneh
    2012-05-16

    Ok, this patch is still bad. It fixes the TEMP issue, but introduces new problems. Now environment vars that were set during the session are getting a prefix of PWD. grrr...

     
  • Orgad Shaneh
    Orgad Shaneh
    2012-05-16

    Hopefully last try :)

     
    Attachments
  • Orgad Shaneh
    Orgad Shaneh
    2012-05-16

    Looks better now. Please review.

     
  • Earnie Boyd
    Earnie Boyd
    2012-05-16

    I've just looked at the patch. It appears to be barking at the wrong tree. Have you built MSYS in debug mode? If so, strace should give you a value for 'returning: %s'.

     
  • Cesar Strauss
    Cesar Strauss
    2012-06-07

    Your patch interferes with path translation of the command-line. Consider the following program, that prints its arguments:

    #include <stdio.h>

    int main(int argc, char * argv[])
    {
    int i;
    for (i=1; i<argc;i++)
    printf("argv[%d]=%s\n",i,argv[i]);
    return 0;
    }

    Compile it with native (MinGW) gcc, and run on the bash shell:
    ./arg /tmp /c

    Expected result:
    argv[0]=c:\rascunho\msys\home\cstrauss\arg.exe
    argv[1]=C:/Users/cstrauss/AppData/Local/Temp
    argv[2]=/c

    After your patch:
    argv[0]=C:\rascunho\msys\home\cstrauss\arg.exe
    argv[1]=C:\Users\cstrauss\AppData\Local\Temp
    argv[2]=\c

    In particular, the //c -> \c conversion breaks usage of command-line switches, like "cmd //c echo /", which is unacceptable.

    The conversion to backslashes of file paths on the command line (argv[1] above) might be acceptable, however. What the others think?

    As I understand it, the issue on this ticket is due to a double path conversion (native->POSIX->native) losing information about the slashes. When entering MSYS, a few variables are converted to POSIX format, like TEMP and PATH. When invoking a native program, all environment variables are converted back to native format, including TEMP and PATH. However the conversion is always done with forward slashes (except path lists, where backslashes are used). A solution is to always convert to backslashes, but this would affect the command line as well, I think.

    Cesar

     
  • Cesar Strauss
    Cesar Strauss
    2012-06-07

    The test program I used was actually:

    #include <stdio.h>

    int main(int argc, char * argv[])
    {
    int i;
    for (i=0; i<argc;i++)
    printf("argv[%d]=%s\n",i,argv[i]);
    return 0;
    }

     
  • Cesar Strauss
    Cesar Strauss
    2012-06-07

    The test actually was:

    ./arg /tmp //c

    Expected result:
    argv[0]=c:\rascunho\msys\home\cstrauss\arg.exe
    argv[1]=C:/Users/cstrauss/AppData/Local/Temp
    argv[2]=/c

    After your patch:
    argv[0]=C:\rascunho\msys\home\cstrauss\arg.exe
    argv[1]=C:\Users\cstrauss\AppData\Local\Temp
    argv[2]=\c

     
<< < 1 2 3 4 5 > >> (Page 4 of 5)