Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

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

(1/1)

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:


--- 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;
}
--- End code ---

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:
Have you tried to escape the quotes in cb?

notonroof:

--- Quote from: oBFusCATed on December 29, 2014, 01:13:52 am ---Have you tried to escape the quotes in cb?

--- End quote ---

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?

--- End quote ---
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)?

Navigation

[0] Message Index

Go to full version