Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: notonroof on December 28, 2014, 08:10:18 pm

Title: Loss of information when passing program arguments from Code::Blocks in Windows.
Post by: notonroof on December 28, 2014, 08:10:18 pm
Hello, here I am,

SVN version issues does not work for me (getting error "The topic or board you are looking for appears to be either missing or off limits to you."), so i am posting this issue here:

Test program:

Code
// test.cpp
#include <stdio.h>
#include <windows.h>

int main()
{
    const char* s = GetCommandLine(); // WinAPI function to get RAW command line
    printf( "%s\n", s );
    return 0;
}

Test case 1 - Executed from command line: test.exe "hello"
Test case 2 - Executed from Code::Blocks with program arguments: "hello"

Output of test case 1: test.exe "hello"
Output of test case 2: test.exe hello

As you can see, in test case 2 quotes somewhere lost.
Title: Re: Loss of information when passing program arguments from Code::Blocks in Windows.
Post by: oBFusCATed on December 29, 2014, 01:13:52 am
Have you tried to escape the quotes in cb?
Title: Re: Loss of information when passing program arguments from Code::Blocks in Windows.
Post by: notonroof on December 29, 2014, 08:22:54 am
Have you tried to escape the quotes in cb?

Thanks. Escaping with backslashes works. ( \"hello\" )

Why it must be escaped in Code::Blocks and it's not instead passed to commandline directly as it is?
( For comparison other GUI windows programs for example Run from start menu or Total Commander passes commandline as it is entered, no quote is removed, no escape needed (If used GetCommandLine() function )  ) )
Title: Re: Loss of information when passing program arguments from Code::Blocks in Windows.
Post by: notonroof on December 29, 2014, 08:39:16 am
Why it must be escaped in Code::Blocks and it's not instead passed to commandline directly as it is?
I ask differently:

Is this behavior of passing program arguments ( removing quotes if its not escaped ) arbitrary choice of one Code::Blocks programer and can be changed if I or someone else send patch?
Or there is deeper reason why it works this way and cannot be changed?
Title: Re: Loss of information when passing program arguments from Code::Blocks in Windows.
Post by: oBFusCATed on December 29, 2014, 03:30:41 pm
I'm not sure.
What is the type of your application (console, gui or native)?