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

English support forum

Moderators: Stefan2, white, sheep, Hacker

aequilibris
Junior Member
Junior Member
Posts: 6
Joined: 2019-02-21, 17:37 UTC

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

Post by *aequilibris » 2019-02-21, 17:40 UTC

The next cmd command successfully opens a file in the right panel of TC:

Code: Select all

start /b cmd /c "C:\Program Files (x86)\totalcmd9\TOTALCMD64.EXE" /O /R=PATH
It works, provided that the PATH does not contain spaces. How to get the command work for a path, which contains spaces ? The use of "PATH" or 'PATH' does not work, as well as other typically used tricks. Is there any solution ?
Last edited by aequilibris on 2019-02-21, 22:05 UTC, edited 1 time in total.

User avatar
Ovg
Power Member
Power Member
Posts: 587
Joined: 2014-01-06, 16:26 UTC
Location: MOW

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

Post by *Ovg » 2019-02-21, 18:01 UTC

add C:\Program Files (x86)\totalcmd9 to you PATH environment variable and

Code: Select all

start /b cmd /c TOTALCMD64.EXE /O /R="PATH"
will work
It's impossible to lead us astray for we don't care even to choose the way.
#259941, TC 9.21a x64, Windows 7 SP1 x64

aequilibris
Junior Member
Junior Member
Posts: 6
Joined: 2019-02-21, 17:37 UTC

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

Post by *aequilibris » 2019-02-21, 18:41 UTC

I shall try that as a last resort (even if it is unclear, why it should work). However still, is it possible to avoid to use environment variables ?
Moreover, would the next variant work ?

Code: Select all

start /b cmd /c TOTALCMD64.EXE /O /L="PATH1" /R="PATH2"
UPD. Thank you Ovg, I tried your method. It works, also for the variant with PATH1 and PATH2. Still, is it a way to do it without the environmental variable ?

User avatar
Ovg
Power Member
Power Member
Posts: 587
Joined: 2014-01-06, 16:26 UTC
Location: MOW

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

Post by *Ovg » 2019-02-21, 18:54 UTC

Environmental variable Path already exist in your system (whether you want it or not and not only in your). Why not using it?
It's impossible to lead us astray for we don't care even to choose the way.
#259941, TC 9.21a x64, Windows 7 SP1 x64

User avatar
Stefan2
Power Member
Power Member
Posts: 2437
Joined: 2007-09-13, 22:20 UTC
Location: Europa

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

Post by *Stefan2 » 2019-02-21, 18:59 UTC

Is there a reason why you use start AND cmd ?
I never use that and do not get the benefit.

and
To avoid problems with spaces in your PATH, quote that like "PATH".

But since you call two interpreter (start.exe and cmd.exe) me guess one or each of them remove the outer quotes,
so try to double the quotes,... maybe smtg like
start /b cmd /c " "C:\Program Files (x86)\totalcmd9\TOTALCMD64.EXE" /O /R="PATH" "



Don't know for sure.

EDIT:
please note that START.exe use the first quoting for the window title,
I don't know if that is still true for smtg like your nested code:
start /b cmd /c "C:\Program Files (x86)\totalcmd9\TOTALCMD64.EXE" /O /R="PATH"
but maybe just try
start "" /b cmd /c "C:\Program Files (x86)\totalcmd9\TOTALCMD64.EXE" /O /R="PATH"




 

User avatar
Dalai
Power Member
Power Member
Posts: 6535
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, 19:22 UTC

Stefan2 wrote:
2019-02-21, 18:59 UTC
But since you call two interpreter (start.exe and cmd.exe) me guess
There is no start.exe. START is an internal command of CMD.

Nevertheless you're right about the quoting and the weirdness of using START to call CMD itself, and it gets stranger when you know that START is an internal command (so CMD essentially calls CMD, which is ... uhm... superfluous).

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

Plugins: Services2, Startups

aequilibris
Junior Member
Junior Member
Posts: 6
Joined: 2019-02-21, 17:37 UTC

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

Post by *aequilibris » 2019-02-21, 19:42 UTC

Ovg wrote:
2019-02-21, 18:54 UTC
Environmental variable Path already exist in your system (whether you want it or not and not only in your). Why not using it?
It is just unnerving that I could not pass a parameter in quotes without resorting to the method above, i.e. by removing the quotes in an other path. It works, but why ? It does not seems logical. The initial syntax should have worked. In any case, thank you, Ovg, for your practical proposal.
Stefan2 wrote:
2019-02-21, 18:59 UTC
Is there a reason why you use start AND cmd ?
Just my ignorance. Once I have composed a working line from directives, which I picked up, and while it is working, I do not change it :). Indeed, the same line works without the "start /b" header.
Stefan2 wrote:
2019-02-21, 18:59 UTC
To avoid problems with spaces in your PATH, quote that like "PATH".
...
start /b cmd /c " "C:\Program Files (x86)\totalcmd9\TOTALCMD64.EXE" /O /R="PATH" "
I am quite ignorant in this area, but I do believe that start does not interfere in terms of parsing of the subsequent expression by cmd (as pointed out by Dalai). If I remove "start /b" everything behaves similarly. However, to my utmost surprise, your method of using doubly nested paths is working !

Code: Select all

cmd /c ""C:\Program Files (x86)\totalcmd9\TOTALCMD64.EXE" /O /R="PATH""
I do not know why it is so, but at least this trick has a general value for me, as it shows the way to "force" the passing of the parameters in such cases.

Thank you very much, Stefan2.

User avatar
Hacker
Moderator
Moderator
Posts: 11195
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

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

Post by *Hacker » 2019-02-21, 19:56 UTC

aequilibris,

Code: Select all

"C:\Program Files (x86)\totalcmd9\TOTALCMD64.EXE" /O "/R=PATH"

Code: Select all

"C:\Program Files (x86)\totalcmd9\TOTALCMD64.EXE" /O /R="PATH"
both work completely fine here.

Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.

aequilibris
Junior Member
Junior Member
Posts: 6
Joined: 2019-02-21, 17:37 UTC

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

Post by *aequilibris » 2019-02-21, 20:00 UTC

Hacker wrote:
2019-02-21, 19:56 UTC

Code: Select all

"C:\Program Files (x86)\totalcmd9\TOTALCMD64.EXE" /O "/R=PATH"

Code: Select all

"C:\Program Files (x86)\totalcmd9\TOTALCMD64.EXE" /O /R="PATH"
Roman, unfortunately neither case is working. I have just checked. Moreover, the second case was the one, I have reported as not working right in the first message.

User avatar
Dalai
Power Member
Power Member
Posts: 6535
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, 20:08 UTC

2aequilibris
One really important thing about the START command: The first quoted parameter it sees is taken as a window title for the newly created process! That's why it works without quoting anything, and it doesn't when quoting a parameter. I'm sure there are examples on the internet that take this behavior into account and use something like

Code: Select all

start [/wait] "" "command with spaces.exe"
or with a title

Code: Select all

start [/wait] "useless title" "command with spaces.exe"
or similar.

Another thing: Why use CMD at all

Code: Select all

cmd /c ""C:\Program Files (x86)\totalcmd9\TOTALCMD64.EXE" /O /R="PATH""
?
This should work the same:

Code: Select all

"C:\Program Files (x86)\totalcmd9\TOTALCMD64.EXE" /O /R="PATH"
And it even has the advantage of not opening a CMD window at all (and avoid "flashing" of such window).

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: 347
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, 21:13 UTC

Dalai wrote:
2019-02-21, 20:08 UTC
Another thing: Why use CMD at all
Try to autostart some program minimized using entry in registry key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

For example add entry for task manager:

Code: Select all

start "" /min C:\WINDOWS\system32\taskmgr.exe
Regards from Poland
Andrzej P. Wozniak

User avatar
Dalai
Power Member
Power Member
Posts: 6535
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, 21:19 UTC

Usher wrote:
2019-02-21, 21:13 UTC
Try to autostart some program minimized using entry in registry key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
How does CMD itself help with that? The START command can do that (start /min), but CMD without START can't and doesn't. Apart from that, I'd rather use something like NirCmd or Cmdow, or use an LNK file with minimized flag in the start menu.

The command line my question was about didn't use the START command, that's why I asked why CMD use at all. And, BTW, I don't think this is about autostart (but I might be wrong).

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

Plugins: Services2, Startups

aequilibris
Junior Member
Junior Member
Posts: 6
Joined: 2019-02-21, 17:37 UTC

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

Post by *aequilibris » 2019-02-21, 21:45 UTC

Dalai wrote:
2019-02-21, 20:08 UTC
2aequilibris
One really important thing about the START command: The first quoted parameter it sees is taken as a window title
I guess, if there is one. In any case, I have tested the previous examples also without the start command. I have found no difference with the shortened version, i.e. starting with cmd. It seems, that the use of start cannot be held responsible.
Dalai wrote:
2019-02-21, 20:08 UTC
Another thing: Why use CMD at all
Dalai, thank you for educating me on this point. I had a feeling that one need a kind of 'executing directive'. However, it is superfluous and indeed, your version is working. Still, sometimes, it is nice to use command keys, e.g. with cmd, and good to know a method to pass the parameters, even if they contain spaces.

P.S. I am sorry for repeatedly demonstrating my ignorance regarding knowledge of Window's command prompt. However, I am very grateful for all your answers, and may be that thread will be useful for someone like me.

User avatar
Hacker
Moderator
Moderator
Posts: 11195
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

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

Post by *Hacker » 2019-02-21, 21:50 UTC

aequilibris,
Moreover, the second case was the one, I have reported as not working right in the first message.
I know, I am just saying it works fine here, so there must be a problem elsewhere (not with the syntax itself).
Roman, unfortunately neither case is working. I have just checked.
Can you perhaps create a video of what is happening?

Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.

aequilibris
Junior Member
Junior Member
Posts: 6
Joined: 2019-02-21, 17:37 UTC

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

Post by *aequilibris » 2019-02-21, 22:03 UTC

To Hacker: I am not sure, whether it is even worth to mention, but when I execute a .bat file with

Code: Select all

cmd /c "C:\Program Files (x86)\totalcmd9\TOTALCMD64.EXE" /O /R="PATH"
the cmd window returns me

Code: Select all

'C:\Program' is not recognized as an internal or external command, operable program or batch file

Post Reply