QB64.org Forum

QB64 Team Software => InForm Discussion => Topic started by: mohai on February 23, 2022, 02:02:12 pm

Title: Bug in shell parameters with backslash
Post by: mohai on February 23, 2022, 02:02:12 pm
Hello,

I think I found a bug when parsing parameters to a SHELL command.
As far as I know, it only happens under Inform programs, not no regular console programs.

If you call a program using the SHELL function and add some parameters, it is advisable to do it in quotes, as spaces will separate different parameters.
If you parse a path as a parameter (enclosed in quotes), sometimes it happens that the backslash is lost and the called program does not receive it, so the rest of parameters come distorted.

I do not know if this is related to some C++ text processing, such as the "\something" for control characters ("\n" for new line, etc).

Example:
    shell "myprogram "+chr$(34)+"C:\"+chr$(34)

I attached an example to show how it works and a simple workaround to drive it.
If you add a space after the "\", the problem does not happen.

I am using the last version of both QB64 (2.0.2) and InForm 1.3
Title: Re: Bug in shell parameters with backslash
Post by: RhoSigma on February 23, 2022, 04:50:48 pm
Without further testing I'd say this is a bad side effect regarding the fact, that our BASIC programs are first translated into C++ before they are actually compiled into a EXE.

Now look at your example shell "myprogram "+chr$(34)+"C:\"+chr$(34) ...

There you've the sequence \", which is a C++ escape/masking sequence for the quote char. What C++ does here is to replace the \" with a single ", and bang, the \ is gone.

Solution:
Avoid the combination \", or try a double backslash in those situations \\", hence one \ will go away by C++ its replacement but the other one remains as you want.

Title: Re: Bug in shell parameters with backslash
Post by: mohai on February 24, 2022, 06:23:12 am
Without further testing I'd say this is a bad side effect regarding the fact, that our BASIC programs are first translated into C++ before they are actually compiled into a EXE.

Now look at your example shell "myprogram "+chr$(34)+"C:\"+chr$(34) ...

There you've the sequence \", which is a C++ escape/masking sequence for the quote char. What C++ does here is to replace the \" with a single ", and bang, the \ is gone.

Solution:
Avoid the combination \", or try a double backslash in those situations \\", hence one \ will go away by C++ its replacement but the other one remains as you want.

Yes, double backslash works too.

In my opinion, this is a bug, as text in a command line should not be processed in any way.

I am sorry I am always complaining about bugs. I do not want to become a "Bug Hunter" or whatever XD
I appreciate the hard work behind QB64.

I will post soon a new application I hope will be useful for you all.