News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Loss of information when passing program arguments from Code::Blocks in Windows.

Started by notonroof, December 28, 2014, 08:10:18 PM

Previous topic - Next topic

notonroof

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:

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

oBFusCATed

(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

notonroof

Quote from: oBFusCATed on December 29, 2014, 01:13:52 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 )  ) )

notonroof

Quote from: notonroof on December 29, 2014, 08:22:54 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?

oBFusCATed

I'm not sure.
What is the type of your application (console, gui or native)?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]