Possible IDE Command Line Bug?

Linux specific forum
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Possible IDE Command Line Bug?

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

Code: Select all

foo="foo bar"
...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?
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Possible IDE Command Line Bug?

Post 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) +"+"
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Possible IDE Command Line Bug?

Post 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.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Possible IDE Command Line Bug?

Post 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.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Possible IDE Command Line Bug?

Post 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. :P
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...
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Possible IDE Command Line Bug?

Post 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.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Possible IDE Command Line Bug?

Post 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.
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Re: Possible IDE Command Line Bug?

Post by helpy »

command line:

Code: Select all

foo="foo bar"
test with purebasic programm on windows 7 command line (not from IDE) results in:

Code: Select all

+foo="foo+
+bar"

I tried this with an windows batch program. This results in:

Code: Select all

+foo+
+"foo bar"+
Here my batch file for the test:

Code: Select all

@echo off
:LOOP
if "%~1" EQU "" goto :EOF
echo +%1+
shift
goto :LOOP
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Re: Possible IDE Command Line Bug?

Post by helpy »

Windows 10 / Windows 7
PB Last Final / Last Beta Testing
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Possible IDE Command Line Bug?

Post 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?
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Possible IDE Command Line Bug?

Post 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:

Code: Select all

foo= "foo bar"
and it will give you two parameters.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Possible IDE Command Line Bug?

Post 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. :mrgreen:
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Post Reply