[Solved] How to pass a parameter with a space (e.g. file name) ?

English support forum

Moderators: Stefan2, white, sheep, Hacker

User avatar
Usher
Senior Member
Senior Member
Posts: 342
Joined: 2011-03-11, 10:11 UTC

Re: How to pass a parameter with a space (e.g. file name) ?

Post by *Usher » 2019-02-21, 22:05 UTC

2Dalai
1. Watch the quantifiers, please. You did ask a general question using "at all". You should ask a specific question using "in this case" instead.

2. It's possible security issue:
* Users are not allowed to install any additional tool on any computer. Let them know how to use system tools in such cases.
* If "start" or "cmd" is needed in any batch, script, etc. which will be run many times, I prefer to use CMD with full path to prevent possible hijacking by malware.
Regards from Poland
Andrzej P. Wozniak

User avatar
Dalai
Power Member
Power Member
Posts: 6532
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: How to pass a parameter with a space (e.g. file name) ?

Post by *Dalai » 2019-02-21, 22:17 UTC

2aequilibris
Correct. The whole quoted part is passed as one command line to cmd.exe, which splits it at spaces (and other delimiters). Hence the about 'C:\Program' not being found. To solve this you need to quote the entire thing again:

Code: Select all

cmd /c ""C:\Program Files (x86)\totalcmd9\TOTALCMD64.EXE" /O /R="PATH""
It might even be necessary to use triple quotes, but I'm too lazy right now to test that.

BTW: if you already are in a batch file, you don't need cmd /c, unless you want to do something advanced or fancy.

2Usher
Please, read the entire context I'm writing about. This includes the code section I was refering to (and even part of the question), which made it clear that the use of CMD was not necessary at all (in this context). And, again, I already assumed that it's not about autostarts, so no need to take that into account.

2. Neither NirCmd nor Cmdow require installation. And, it may be a security risk to create a startup as user, so ... pick your poison. Although you're not wrong to use tools that come with Windows, it's good to know that there are (much) better tools out there, which often make things much easier and faster to get the job done.

Regards
Dalai
#101164 Personal licence
Athlon X4 880K, 16 GiB RAM, Gigabyte F2A88X-D3HP, Win7 x64

Plugins: Services2, Startups

User avatar
Usher
Senior Member
Senior Member
Posts: 342
Joined: 2011-03-11, 10:11 UTC

Re: How to pass a parameter with a space (e.g. file name) ?

Post by *Usher » 2019-02-21, 22:42 UTC

Dalai wrote:
2019-02-21, 22:17 UTC
2aequilibris

Code: Select all

cmd /c ""C:\Program Files (x86)\totalcmd9\TOTALCMD64.EXE" /O /R="PATH""
Really?
Let's start here, in MS docs: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/cmd
MS Docs wrote: Processing quotation marks

If you specify /c or /k, cmd processes the remainder of String, and quotation marks are preserved only if all of the following conditions are met:

You do not use /s.
You use exactly one set of quotation marks.
You do not use any special characters within the quotation marks (for example: & < > ( ) @ ^ | ).
You use one or more white-space characters within the quotation marks.
The String within quotation marks is the name of an executable file.

If the previous conditions are not met, String is processed by examining the first character to verify whether it is an opening quotation mark. If the first character is an opening quotation mark, it is stripped along with the closing quotation mark. Any text following the closing quotation marks is preserved.
Which cmd version allows to use more than a single pair of quotation marks or to use them for non-exe part of command line? Some malware maybe?
Dalai wrote:
2019-02-21, 22:17 UTC
2Usher
Please, read the entire context I'm writing about.
Once again, be very careful with quantifiers, please.
Don't make a bigger mess, it's highly illogical, Captain Dalai.
Regards from Poland
Andrzej P. Wozniak

User avatar
Dalai
Power Member
Power Member
Posts: 6532
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: How to pass a parameter with a space (e.g. file name) ?

Post by *Dalai » 2019-02-21, 23:07 UTC

Usher wrote:
2019-02-21, 22:42 UTC
Really?
Let's start here
Did you read and understand what MS writes? Did you TEST it? There is NOT a single executable in quotes, because the command line contains parameters to that executable. Furthermore, there's not ONE set of quotes but TWO, although they're not nested. Do you know which path is passed to TC in that command line and whether or not that contains any of the special characters MS mentions? I don't know, so I make sure the quotes are preserved by doubling them. So you see, only a minor part of conditions is met, and with only one pair of quotes, the command line just doesn't work because the first and last one are stripped, and that's why CMD looks for C:\Program[.exe].

Believe me when I say that I've been working for a long time with CMD and batch scripts, so I know what works and what doesn't.
Don't make a bigger mess, it's highly illogical, Captain Dalai.
It's highly illogical to ask in this thread related to this topc if something makes sense in conjunction with this topic? Strange point of view, sorry.

Regards
Dalai
#101164 Personal licence
Athlon X4 880K, 16 GiB RAM, Gigabyte F2A88X-D3HP, Win7 x64

Plugins: Services2, Startups

Post Reply