Author Topic: Loss of information when passing program arguments from Code::Blocks in Windows.  (Read 3499 times)

Offline notonroof

  • Single posting newcomer
  • *
  • Posts: 7
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Have you tried to escape the quotes in cb?
(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!]

Offline notonroof

  • Single posting newcomer
  • *
  • Posts: 7
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 )  ) )

Offline notonroof

  • Single posting newcomer
  • *
  • Posts: 7
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?
« Last Edit: December 29, 2014, 08:41:00 am by notonroof »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
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!]