public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* RE: Argument parsing with gcc compiled program
@ 2015-11-26 21:20 Gluszczak, Glenn
  2015-11-27 10:10 ` Jan Nijtmans
  0 siblings, 1 reply; 10+ messages in thread
From: Gluszczak, Glenn @ 2015-11-26 21:20 UTC (permalink / raw)
  To: cygwin



Sorry I should have specified, this is not bash as this happens with the gcc compiled
program within a Command Prompt session.


K:\>a.exe -s something "something d\:\\hello"

Command-line arguments:
  argv[0]   a
  argv[1]   -s
  argv[2]   something
  argv[3]   something d\:\hello
CL: K:\sat-misc\src\sat-main\sat\src\wiz\a -s something "something d\:\hello"


==============================================================


For some reason when I compile a C program in gcc, double backslashes within quotes are stripped.
But if I compile with Visual Studio this does not happen.  I used a small test program to demonstrate.

VS
c:\msvc2010_SP1\VC>a.exe -s something "something d\:\\hello"

Command-line arguments:
  argv[0]   a.exe
  argv[1]   -s
  argv[2]   something
  argv[3]   something d\:\\hello
CL: a.exe  -s something "something d\:\\hello"


GCC
$ ./a.exe -s something "something d\:\\hello"

Command-line arguments:
  argv[0]   ./a
  argv[1]   -s
  argv[2]   something
  argv[3]   something d\:\hello
CL: K:\sat-misc\src\sat-main\sat\src\wiz\a -s something "something d\:\hello"



Is there some compiler option or setting I'm unaware of?
Thanks,
Glenn

===============================================================================


#include <Windows.h>
#include <stdio.h>

int main( int argc, // Number of strings in array argv
 char *argv[],      // Array of command-line argument strings
 char **envp )      // Array of environment variable strings
{
    int count;
   char *gcl;

    // Display each command-line argument.
    printf("   \nCommand-line arguments:\n" );
    for( count = 0; count < argc; count++ )
        printf( "  argv[%d]   %s\n", count, argv[count] );

 
    gcl = GetCommandLine();
    printf("CL: %s\n",gcl);
}


--
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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Argument parsing with gcc compiled program
  2015-11-26 21:20 Argument parsing with gcc compiled program Gluszczak, Glenn
@ 2015-11-27 10:10 ` Jan Nijtmans
  2015-11-27 16:34   ` Gluszczak, Glenn
  2015-11-27 17:08   ` Gluszczak, Glenn
  0 siblings, 2 replies; 10+ messages in thread
From: Jan Nijtmans @ 2015-11-27 10:10 UTC (permalink / raw)
  To: cygwin

2015-11-26 21:30 GMT+01:00 Gluszczak, Glenn <glenn.gluszczak@emc.com>:
> Sorry I should have specified, this is not bash as this happens with the gcc compiled
> program within a Command Prompt session.
>
>
> K:\>a.exe -s something "something d\:\\hello"
>
> Command-line arguments:
>   argv[0]   a
>   argv[1]   -s
>   argv[2]   something
>   argv[3]   something d\:\hello
> CL: K:\sat-misc\src\sat-main\sat\src\wiz\a -s something "something d\:\hello"

I think it's both "bash" and "cmd.exe" who do backslash substitution, even
though they don't follow the same rules. gcc cannot do anything about it.

See:
<http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx>

Regards,
          Jan Nijtmans

--
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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: Argument parsing with gcc compiled program
  2015-11-27 10:10 ` Jan Nijtmans
@ 2015-11-27 16:34   ` Gluszczak, Glenn
  2015-11-27 16:55     ` Csaba Raduly
  2015-11-27 17:08   ` Gluszczak, Glenn
  1 sibling, 1 reply; 10+ messages in thread
From: Gluszczak, Glenn @ 2015-11-27 16:34 UTC (permalink / raw)
  To: cygwin

>-----Original Message-----
>From: Jan Nijtmans [mailto:jan.nijtmans@gmail.com] 
>Sent: Friday, November 27, 2015 4:30 AM
>To: cygwin@cygwin.com
>Subject: Re: Argument parsing with gcc compiled program
>
>2015-11-26 21:30 GMT+01:00 Gluszczak, Glenn <glenn.gluszczak@emc.com>:
>> Sorry I should have specified, this is not bash as this happens with 
>> the gcc compiled program within a Command Prompt session.
>>
>>
>> K:\>a.exe -s something "something d\:\\hello"
>>
>> Command-line arguments:
>>   argv[0]   a
>>   argv[1]   -s
>>   argv[2]   something
>>   argv[3]   something d\:\hello
>> CL: K:\sat-misc\src\sat-main\sat\src\wiz\a -s something "something d\:\hello"
>
>I think it's both "bash" and "cmd.exe" who do backslash substitution, even though they don't follow the same rules. gcc cannot do >anything about it.
>
>See:
><http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx>

>Regards,
>          Jan Nijtmans


The parsing rules clearly state that arguments are only affected by quotes.
"Backslashes are interpreted literally, unless they immediately precede a double quotation mark."
https://msdn.microsoft.com/en-us/library/17w5ykft.aspx

Please look at my example again.  The same program compiled with Visual Studio does *not*
strip out the backslash whether run in cmd.exe or bash.exe.  Other utilities like Perl
do not strip out the backslash either.  It is only programs I compile with Cygwin gcc that do this.

Glenn

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Argument parsing with gcc compiled program
  2015-11-27 16:34   ` Gluszczak, Glenn
@ 2015-11-27 16:55     ` Csaba Raduly
  0 siblings, 0 replies; 10+ messages in thread
From: Csaba Raduly @ 2015-11-27 16:55 UTC (permalink / raw)
  To: cygwin list

On Fri, Nov 27, 2015 at 5:03 PM, Gluszczak, Glenn  wrote:

> Please look at my example again.  The same program compiled with Visual Studio does *not*
> strip out the backslash whether run in cmd.exe or bash.exe.  Other utilities like Perl
> do not strip out the backslash either.  It is only programs I compile with Cygwin gcc that do this.

Windows Perl or Cygwin Perl ?

Csaba
-- 
GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ w++$ tv+ b++ DI D++ 5++
The Tao of math: The numbers you can count are not the real numbers.
Life is complex, with real and imaginary parts.
"Ok, it boots. Which means it must be bug-free and perfect. " -- Linus Torvalds
"People disagree with me. I just ignore them." -- Linus Torvalds

--
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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: Argument parsing with gcc compiled program
  2015-11-27 10:10 ` Jan Nijtmans
  2015-11-27 16:34   ` Gluszczak, Glenn
@ 2015-11-27 17:08   ` Gluszczak, Glenn
  2015-11-27 17:34     ` Marco Atzeri
  1 sibling, 1 reply; 10+ messages in thread
From: Gluszczak, Glenn @ 2015-11-27 17:08 UTC (permalink / raw)
  To: cygwin

>On Fri, Nov 27, 2015 at 5:03 PM, Gluszczak, Glenn  wrote:

> Please look at my example again.  The same program compiled with Visual Studio does *not*
> strip out the backslash whether run in cmd.exe or bash.exe.  Other utilities like Perl
> do not strip out the backslash either.  It is only programs I compile with Cygwin gcc that do this.

>Windows Perl or Cygwin Perl ?
>
>Csaba

You're correct about Perl, my bad.  My path in my CMD was pointing to Windows Perl.
Windows Perl does not strip out the backslash. Cygwin Perl is stripping out the backslash.

$ cat a.pl
$pcount = 0;
while ( $pcount <= ($#ARGV )) {
    printf("%s\n",$ARGV[$pcount]);
    $pcount ++;
}

$ perl a.pl -s "dsfgdsfgfsg d\:\\hello"
-s
dsfgdsfgfsg d\:\hello

K:\> c:\cygwin\bin\perl a.pl -s "dsfgdsfgfsg d\:\\hello"
-s
dsfgdsfgfsg d\:\hello

So if I compile with MS Visual Studio, binaries do not strip backslashes out of
arguments whether run in bash or cmd.  

If I compile with Cygwin gcc, backslashes are stripped whether in bash or cmd.

This looks like a compiler issue to me unless someone knows of an option.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Argument parsing with gcc compiled program
  2015-11-27 17:08   ` Gluszczak, Glenn
@ 2015-11-27 17:34     ` Marco Atzeri
  0 siblings, 0 replies; 10+ messages in thread
From: Marco Atzeri @ 2015-11-27 17:34 UTC (permalink / raw)
  To: cygwin



On 27/11/2015 17:55, Gluszczak, Glenn wrote:
>> On Fri, Nov 27, 2015 at 5:03 PM, Gluszczak, Glenn  wrote:
>
>> Please look at my example again.  The same program compiled with Visual Studio does *not*
>> strip out the backslash whether run in cmd.exe or bash.exe.  Other utilities like Perl
>> do not strip out the backslash either.  It is only programs I compile with Cygwin gcc that do this.
>
>
> So if I compile with MS Visual Studio, binaries do not strip backslashes out of
> arguments whether run in bash or cmd.
>
> If I compile with Cygwin gcc, backslashes are stripped whether in bash or cmd.
>
> This looks like a compiler issue to me unless someone knows of an option.
>

https://cygwin.com/ml/cygwin/2004-07/msg01036.html

--
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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Argument parsing with gcc compiled program
  2015-11-27 19:02 Gluszczak, Glenn
@ 2015-11-28 10:06 ` Achim Gratz
  0 siblings, 0 replies; 10+ messages in thread
From: Achim Gratz @ 2015-11-28 10:06 UTC (permalink / raw)
  To: cygwin

Gluszczak, Glenn writes:
> Thanks for the email reference.  Cygwin.dll always strips backslashes
> so I'm stuck compiling with VS, ok.

You can do a cross-compile from Cygwin to MinGW if you need Windows
semantics.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Waldorf MIDI Implementation & additional documentation:
http://Synth.Stromeko.net/Downloads.html#WaldorfDocs

--
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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Argument parsing with gcc compiled program
@ 2015-11-27 19:02 Gluszczak, Glenn
  2015-11-28 10:06 ` Achim Gratz
  0 siblings, 1 reply; 10+ messages in thread
From: Gluszczak, Glenn @ 2015-11-27 19:02 UTC (permalink / raw)
  To: cygwin

>* From: Marco Atzeri <marco dot atzeri at gmail dot com>
>* To: cygwin at cygwin dot com
>* Date: Fri, 27 Nov 2015 18:08:44 +0100
>* Subject: Re: Argument parsing with gcc compiled program
>* Authentication-results: sourceware.org; auth=none
>* References: <CAO1jNwu2RXpCn2JuaZEhGaFA4_UTW9dxPxRcoasRuUBwgbRQgA at mail dot gmail dot com> <91DCAC3CB99C724EB365BB64677FBE7B01DFDC >at MX204CL04 dot corp dot emc dot com>
>________________________________________

>On 27/11/2015 17:55, Gluszczak, Glenn wrote:
>On Fri, Nov 27, 2015 at 5:03 PM, Gluszczak, Glenn  wrote:

>Please look at my example again.  The same program compiled with Visual Studio does *not*
>strip out the backslash whether run in cmd.exe or bash.exe.  Other utilities like Perl
>do not strip out the backslash either.  It is only programs I compile with Cygwin gcc that do this.

>So if I compile with MS Visual Studio, binaries do not strip backslashes out of
>arguments whether run in bash or cmd.

>If I compile with Cygwin gcc, backslashes are stripped whether in bash or cmd.

>This looks like a compiler issue to me unless someone knows of an option.

>https://cygwin.com/ml/cygwin/2004-07/msg01036.html


Thanks for the email reference.  Cygwin.dll always strips backslashes so I'm stuck compiling with VS, ok.

--
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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Argument parsing with gcc compiled program
  2015-11-26 20:15 Gluszczak, Glenn
@ 2015-11-26 20:30 ` Marco Atzeri
  0 siblings, 0 replies; 10+ messages in thread
From: Marco Atzeri @ 2015-11-26 20:30 UTC (permalink / raw)
  To: cygwin



On 26/11/2015 21:08, Gluszczak, Glenn wrote:
> For some reason when I compile a C program in gcc, double backslashes within quotes are stripped.
> But if I compile with Visual Studio this does not happen.  I used a small
> test program to demonstrate.
>
> VS
> c:\msvc2010_SP1\VC>a.exe -s something "something d\:\\hello"
>
> Command-line arguments:
>    argv[0]   a.exe
>    argv[1]   -s
>    argv[2]   something
>    argv[3]   something d\:\\hello
> CL: a.exe  -s something "something d\:\\hello"
>
>
> GCC
> $ ./a.exe -s something "something d\:\\hello"
>
> Command-line arguments:
>    argv[0]   ./a
>    argv[1]   -s
>    argv[2]   something
>    argv[3]   something d\:\hello
> CL: K:\sat-misc\src\sat-main\sat\src\wiz\a -s something "something d\:\hello"
>
> Is there some compiler option or setting I'm unaware of?
> Thanks,
> Glenn
>

bash is stripping the double backslashes
when using " , try '

$ ./a.exe -s something 'something d\:\\hello'

Command-line arguments:
   argv[0]   ./a
   argv[1]   -s
   argv[2]   something
   argv[3]   something d\:\\hello
CL: "E:\cygwin64\tmp\a.exe"




--
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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Argument parsing with gcc compiled program
@ 2015-11-26 20:15 Gluszczak, Glenn
  2015-11-26 20:30 ` Marco Atzeri
  0 siblings, 1 reply; 10+ messages in thread
From: Gluszczak, Glenn @ 2015-11-26 20:15 UTC (permalink / raw)
  To: cygwin

For some reason when I compile a C program in gcc, double backslashes within quotes are stripped.
But if I compile with Visual Studio this does not happen.  I used a small
test program to demonstrate.

VS
c:\msvc2010_SP1\VC>a.exe -s something "something d\:\\hello"

Command-line arguments:
  argv[0]   a.exe
  argv[1]   -s
  argv[2]   something
  argv[3]   something d\:\\hello
CL: a.exe  -s something "something d\:\\hello"


GCC
$ ./a.exe -s something "something d\:\\hello"

Command-line arguments:
  argv[0]   ./a
  argv[1]   -s
  argv[2]   something
  argv[3]   something d\:\hello
CL: K:\sat-misc\src\sat-main\sat\src\wiz\a -s something "something d\:\hello"



Is there some compiler option or setting I'm unaware of?
Thanks,
Glenn

===============================================================================


#include <Windows.h>
#include <stdio.h>

int main( int argc, // Number of strings in array argv
 char *argv[],      // Array of command-line argument strings
 char **envp )      // Array of environment variable strings
{
    int count;
   char *gcl;

    // Display each command-line argument.
    printf("   \nCommand-line arguments:\n" );
    for( count = 0; count < argc; count++ )
        printf( "  argv[%d]   %s\n", count, argv[count] );

 
    gcl = GetCommandLine();
    printf("CL: %s\n",gcl);
}


--
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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-11-27 19:24 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-26 21:20 Argument parsing with gcc compiled program Gluszczak, Glenn
2015-11-27 10:10 ` Jan Nijtmans
2015-11-27 16:34   ` Gluszczak, Glenn
2015-11-27 16:55     ` Csaba Raduly
2015-11-27 17:08   ` Gluszczak, Glenn
2015-11-27 17:34     ` Marco Atzeri
  -- strict thread matches above, loose matches on Subject: below --
2015-11-27 19:02 Gluszczak, Glenn
2015-11-28 10:06 ` Achim Gratz
2015-11-26 20:15 Gluszczak, Glenn
2015-11-26 20:30 ` Marco Atzeri

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).