public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Andrey Repin <anrdaemon@yandex.ru>
To: Dmitry Katsubo <dma_k@mail.ru>, cygwin@cygwin.com
Subject: Re: Quotes around command-line argument that has unicode characters are not removed
Date: Thu, 22 Mar 2018 12:24:00 -0000	[thread overview]
Message-ID: <1547310513.20180322142446@yandex.ru> (raw)
In-Reply-To: <08d9621d-b9a0-c0d7-b58b-581ab957a08c@mail.ru>

Greetings, Dmitry Katsubo!

> Dear Cygwin community,

> I observe the following on my Cygwin:

This is not cygwin, this is bare Windows.

> when I put quotes around file that has
> non-ASCII symbols, these quotes are passed to argv of the process literally,
> otherwise they are removed. I would expect that there is a consistency.

Parameter unquoting done by the shell.
CMD does that differently from POSIX shells.

> I have written a small C program that displays arguments, and run it three
> times:

Run it in bash. I'm pretty sure you will see your results more consistent.

> #1 For the file with space, taken into quotes ("the file.txt") -- OK
> #2 For the file with non-ASCII characters (Château.txt) -- OK
> #3 For the file with non-ASCII characters, taken into quotes ("Château.txt") -- WRONG

> d:\cli> uname -a
> CYGWIN_NT-6.1-WOW PC 2.9.0(0.318/5/3) 2017-09-12 10:41 i686 Cygwin

> D:\cli> chcp
> Active code page: 866

> D:\cli> dir
> ...cut...
> 2018-03-22  00:43                 0 Château.txt
> 2018-03-22  00:01               393 test.c
> 2018-03-22  00:01           150,230 test.exe
> 2018-03-21  00:15               186 test.pl
> 2018-03-22  00:43                 0 the file.txt
> 2018-03-22  00:40                16 текст плюс.txt
>                6 File(s)        150,825 bytes
>                2 Dir(s)  41,972,293,632 bytes free

> D:\cli> test "the file.txt"
> param 0 = test
> param 1 = the file.txt
> File 'the file.txt' was opened

> D:\cli> test Château.txt
> param 0 = test
> param 1 = Château.txt
> File 'Château.txt' was opened

> D:\cli> test "Château.txt"
> param 0 = test
> param 1 = "Château.txt"
> Failed to open '"Château.txt"': No such file or directory

> As one can see, the last run fails. I am a bit puzzled: how can I pass the name
> of the file with space and Unicode symbols? I need to do it in uniform way, as I
> am calling a Cygwin program from native Windows program, as in [1].

> D:\cli> test "текст плюс.txt"
> param 0 = test
> param 1 = "текст плюс.txt"
> Failed to open '"текст плюс.txt"': No such file or directory

> I have search a bit, but I couldn't find a direct answer. From post [1] and [2]
> I see that compiler inserts the code to do some argument pre-processing like
> @pathnames [3], but what are exactly the rules? Is quote pre-processing done in
> dcrt0.cc:177 [4]?

> Any feedback is appreciated.

> [1] https://sourceware.org/ml/cygwin/2016-05/msg00082.html
> [2] http://daviddeley.com/autohotkey/parameters/parameters.htm
> [3] https://cygwin.com/cygwin-ug-net/using-specialnames.html#pathnames-at
> [4] https://github.com/openunix/cygwin/blob/master/winsup/cygwin/dcrt0.cc#L177

> === test.c ===
> #include <stdio.h>
> #include <errno.h>
> #include <string.h>

> int main(int argc, char* argv[])
> {
>         for (int i = 0; i < argc; i++)
>         {
>                 printf("param %d = %s\n", i, argv[i]);
>         }
>         FILE* f = fopen(argv[1], "r");
>         if (f != NULL)
>         {
>                 printf("File '%s' was opened\n", argv[1]);
>                 fclose(f);
>         } else {
>                 printf("Failed to open '%s': %s\n", argv[1], strerror(errno));
>         }
>         return 0;
> }



-- 
With best regards,
Andrey Repin
Thursday, March 22, 2018 14:21:25

Sorry for my terrible english...
--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


  reply	other threads:[~2018-03-22 11:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-22  5:41 Dmitry Katsubo via cygwin
2018-03-22 12:24 ` Andrey Repin [this message]
2018-03-22 17:25   ` Kaz Kylheku
2018-03-22 22:46     ` Dmitry Katsubo via cygwin
2018-03-25  0:04       ` Kaz Kylheku
2018-03-22 21:14   ` Dmitry Katsubo via cygwin
2018-03-23  7:58   ` Thomas Wolff
2018-03-23 12:20     ` Steven Penny
2018-03-22 13:35 ` Mikhail Usenko via cygwin
2018-03-22 15:35   ` Andrey Repin
2018-03-22 22:21     ` Dmitry Katsubo via cygwin
2018-03-27 10:05       ` Andrey Repin
2018-03-27 17:39         ` Brian Inglis

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=1547310513.20180322142446@yandex.ru \
    --to=anrdaemon@yandex.ru \
    --cc=cygwin@cygwin.com \
    --cc=dma_k@mail.ru \
    /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).