public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Frank Redeker <frank.redeker@razorcat.com>
To: Corinna Vinschen via Cygwin <cygwin@cygwin.com>
Subject: Re: [EXTERNAL] Re: Strange behavior when executing programs
Date: Mon, 12 Dec 2022 17:40:29 +0100	[thread overview]
Message-ID: <6dae8101-abe2-6ddc-9792-b38e1d689b9b@razorcat.com> (raw)
In-Reply-To: <Y5dLjMP2xGa2UTtO@calimero.vinschen.de>



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


      reply	other threads:[~2022-12-12 16:38 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-12 10:21 Frank Redeker
2022-12-12 12:12 ` Corinna Vinschen
2022-12-12 12:46   ` Frank Redeker
2022-12-12 13:09     ` Corinna Vinschen
2022-12-13  9:51       ` Corinna Vinschen
2022-12-13 12:54         ` Frank Redeker
2022-12-13 14:15           ` Corinna Vinschen
2022-12-13 16:35             ` Frank Redeker
2022-12-13 16:54               ` Jon Turney
2022-12-13 17:04                 ` Oskar Skog
2022-12-14  5:38         ` Frank Redeker
2022-12-14 10:14           ` Corinna Vinschen
2022-12-12 14:52   ` [EXTERNAL] " Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2022-12-12 15:20     ` Corinna Vinschen
2022-12-12 15:29       ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2022-12-12 15:40         ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2022-12-12 15:42         ` Corinna Vinschen
2022-12-12 15:50           ` Corinna Vinschen
2022-12-12 15:22     ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2022-12-12 15:41       ` Corinna Vinschen
2022-12-12 16:40         ` Frank Redeker [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6dae8101-abe2-6ddc-9792-b38e1d689b9b@razorcat.com \
    --to=frank.redeker@razorcat.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).