Author Topic: Bug in shell parameters with backslash  (Read 6058 times)

0 Members and 1 Guest are viewing this topic.

Offline mohai

  • Newbie
  • Posts: 20
    • View Profile
Bug in shell parameters with backslash
« 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
* CommandLineBugTest.zip (Filesize: 2.63 MB, Downloads: 348)

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Bug in shell parameters with backslash
« Reply #1 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.

My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline mohai

  • Newbie
  • Posts: 20
    • View Profile
Re: Bug in shell parameters with backslash
« Reply #2 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.