Page 1 of 1
Possible IDE Command Line Bug?
Posted: Sat Jul 18, 2015 6:26 am
by Shield
Hey There
I'm using 5.24 LTS on Linux (Ubuntu / Gnome) and it seems like there is a bug with the command line parsing with the IDE.
Since I'm not a regular PB user and I'm even less used to using PB on Linux, I decided to put it here first for review.
Enter the following command line in the IDE Compiler Options...
...then run the code:
Code: Select all
count = CountProgramParameters()
For i = 0 To count - 1
Debug "+" + ProgramParameter(i) + "+"
Next
The debug window shows two entries, which is wrong:
+foo="foo+
+bar"+
Correct would be:
+foo=foo bar+
If I compile everything and execute the program via command line, it behaves as expected.
So the fault must lie with the IDE, I guess.
Anything I'm missing?
Re: Possible IDE Command Line Bug?
Posted: Sat Jul 18, 2015 8:25 am
by Vera
Hello Shield,
to me the debug output is plausible as you debug each parameter at a time, so they are debugged one after the other - one output per debug-line.
To add them up to achieve your wanted result, I would do it this way:
Code: Select all
count = CountProgramParameters()
For i = 0 To count - 1
myPara.s = myPara + ProgramParameter(i) + " "
Next
Debug "+"+ RTrim(myPara) +"+"
Re: Possible IDE Command Line Bug?
Posted: Sat Jul 18, 2015 8:33 am
by Shield
The problem is that ProgramParameter() should report only ONE single parameter, not two.
The space within foo="foo bar" is enclosed in double quotes and there is no other spaces separating the words.
If the string was foo= "foo bar" (notice the space after foo=), the output is correct with two arguments "foo=" and "foo bar" (without quotes).
Also, as I've mentioned, if I start the executable file with the command line the command line arguments are parsed correctly.
Re: Possible IDE Command Line Bug?
Posted: Sat Jul 18, 2015 9:25 am
by Vera
Shield wrote:ProgramParameter() should report only ONE single parameter
Ok - but why count them at all, knowing there is supposed to be only ONE? A single debug would have been more telling.
Seems a similar issue like with RunProgram() and passing on
several parameters including wanted spaces.
Shield wrote:Also, as I've mentioned, if I start the executable file with the command line the command line arguments are parsed correctly.
How do you know if you're not just lucky that your passed on spaced-parameter is fully handed over within the first parameterpart.
Re: Possible IDE Command Line Bug?
Posted: Sat Jul 18, 2015 9:45 am
by Shield
Vera wrote:Ok - but why count them at all, knowing there is supposed to be only ONE? A single debug would have been more telling.
I kinda disagree, I bet I would have gotten an answer from someone that's telling me to iterate.

Also it just felt more logical for me since it illustrates the problem with the splitting better (where " is part of the parameter itself).
Vera wrote:How do you know if you're not just lucky that your passed on spaced-parameter is fully handed over within the first parameterpart.
Because there is no luck in programming.
I don't know if parsing command line arguments is standardized on linux among shells / processes
or if each piece of software (also IDE) implements a custom parser. On Windows it always seems to be a quirk too...
Re: Possible IDE Command Line Bug?
Posted: Sat Jul 18, 2015 9:48 am
by Danilo
I think PB takes double-quotes into account only if a parameter starts with it, like: "file name.ext"
foo="foo bar" does not start with double-quotes, so it is 2 separate cmd line parameters.
foo = "foo bar" (with space separators) should be 3 params then: foo, =, "foo bar"
"foo=foo bar" is one cmd line param.
Don't know what influence different shells may have on this.
Re: Possible IDE Command Line Bug?
Posted: Sat Jul 18, 2015 7:59 pm
by Trond
Shield wrote:I don't know if parsing command line arguments is standardized on linux among shells / processes
The parsing is done by the shell (bash).
Aparently the IDE isn't using the shell to run the program, or it somehow escapes the quotes first.
Re: Possible IDE Command Line Bug?
Posted: Sat Jul 18, 2015 8:27 pm
by helpy
command line:
test with purebasic programm on windows 7 command line (not from IDE) results in:
I tried this with an windows batch program. This results in:
Here my batch file for the test:
Code: Select all
@echo off
:LOOP
if "%~1" EQU "" goto :EOF
echo +%1+
shift
goto :LOOP
Re: Possible IDE Command Line Bug?
Posted: Sat Jul 18, 2015 8:32 pm
by helpy
Re: Possible IDE Command Line Bug?
Posted: Sun Jul 19, 2015 5:40 am
by Shield
Interesting. So I guess the proper way would be to quote everything, e.g. "foo=foo bar".
I'd still like to know how the IDE is handling this. Custom parsing?
Re: Possible IDE Command Line Bug?
Posted: Sun Jul 19, 2015 10:40 am
by Trond
Shield wrote:Interesting. So I guess the proper way would be to quote everything, e.g. "foo=foo bar".
That would give you everything as one parameter. If I type this "apple and oranges" "foo=foo bar" I get the quoted parts as a parameter each.
foo="foo bar" should give two parameters.
I'd still like to know how the IDE is handling this. Custom parsing?
Apparently, yes. And it only considers quotes preceded by a space to open a quoted parameter.
So you can work around this problem by putting in this in the IDE:
and it will give you two parameters.
Re: Possible IDE Command Line Bug?
Posted: Sun Jul 19, 2015 10:51 am
by Shield
Trond wrote:foo="foo bar" should give two parameters.
I disagree, I think one resulting parameter would be correct since it's only one string, not separated by spaces.
In the long run, however, I think this is not of my concern since I can just expect my program to get correctly formatted parameters by the user.
