[EXTERNAL] Re: Strange behavior when executing programs

Frank Redeker frank.redeker@razorcat.com
Mon Dec 12 16:40:29 GMT 2022



Am 12/12/2022 um 4:41 PM schrieb Corinna Vinschen via Cygwin:
> On Dec 12 15:22, Lavrentiev, Anton (NIH/NLM/NCBI) [C] via Cygwin wrote:
>> Sorry about the earlier typos
>>
>>> (and, hence, I suppose for the purposes of the OP).
>>
>> and, hence, I suppose, *would work* for the purposes of the OP.
>>
>>> Since realpath is supposed to resolve all symlinks,
>>
>> I meant by default (the -P behavior).  If -s was asked, then the output would be corect.
> 
> Options are only available in realpath(1).  As for under the hood,
> realpath(3) has no options so it can only return one of the
> alternatives.
> 
> 
> Corinna
> 
I don't have a problem with *realpath* but with the fact that a native 
program in a cygwin or msys shell gives a different result than in a 
Windows CMD or older versions of cygwin and msys.

Consider the following simple sample unsing the WIN32 API. (Compiled 
with MinGW, Borland, Visual Studio, ....)

#include <windows.h>
#include <stdio.h>

int main(int argc, char ** argv) {
    char     buffer[PATH_MAX];

    argc--; argv++;
    if (argc) {
       char *   dummy;

       GetFullPathName(*argv, sizeof(buffer), buffer, &dummy);
       printf("[%s] -> [%s]\n", *argv, buffer);
    }

    return 0;
}

If I execute the program from inside CMD it gives the expected result.

S:\ado>sample msadox.dll
[msadox.dll] -> [S:\ado\msadox.dll]

 From inside a bash the result depends on passed argument and/or the 
current working directory of the shell.

f.redeker@MIMIR-2 /cygdrive/s/ado
$ sample msadox.dll
[msadox.dll] -> [C:\Program Files\Common Files\System\ado\msadox.dll]

With Process Monitor I have observed that the shell does not execute the 
program directly, but starts a subshell and that subshell then starts 
the actual program.

The created Windows Process has as working directory not S:\ado but 
C:\Program Files\Common Files\System\ado.

But if the first argument of GetFullPathName() is a relative path, then 
Windows takes into account the in my eyes incorrect working directory. 
The same thing happens when you use GetCurrentDirectory() in your program.


Frank



More information about the Cygwin mailing list