Reputation: 17049
I need to run
start cmd.exe /k "C:\Program Files (x86)\Mozilla Firefox\sdk\bin\activate & cd d:\home\name\addon\ & cfx run"
The problem is that first path has spaces (Program Files
). I can't use quotes, because they are used for full command already.
How can I use spaces in this command?
Upvotes: 17
Views: 86447
Reputation: 1
This worked with Win 7 Home: start cmd.exe /c "C:\RemoveDrive\RemoveDrive G:"
I could not make Win 7 Pro run a .bat file with any space in the path or as part of the executable ("RemoveDrive :G"). So I made RunEjectG.bat to run EjectG.bat.
It's a workaround,but I could not spend more time to solve the problem.
note: the /c
switch closes the cmd window after running the bat, a /k
switch leaves cmd window open.
Upvotes: 0
Reputation: 1
start cmd.exe /k "" "C:\Program Files (x86)\Mozilla Firefox\sdk\bin\activate & cd d:\home\name\addon\ & cfx run"
Add those two extra quotes before the filepath. That usually works for me. Good luck :)
Upvotes: 0
Reputation: 36451
Use quotes for the first path and escape them with ^
:
start cmd.exe /k "^"C:\Program Files (x86)\Mozilla Firefox\sdk\bin\activate^" & cd d:\home\name\addon\ & cfx run"
EDIT:
Concerning @dbenham 's comment:
Interesting. Escaping with ^
did work for me, although my actual command was slightly different because I tested it with the first command that came into my mind.
This works on my machine (Windows XP SP 3):
start cmd.exe /k "xcopy ^"C:\Program Files\Windows Live\Messenger\license.rtf^" c:\"
I also read about escaping using double quotes ""
, but that didn't work for me with my above example.
Then again, I'm no batch file guru and maybe cmd.exe
behaves differently when you use &
(which I never heard about before).
Upvotes: 0
Reputation: 130919
Who says you can't add quotes around the exe path when the /C command is already quoted? It works fine ! :-)
start cmd.exe /k ""C:\Program Files (x86)\Mozilla Firefox\sdk\bin\activate" & cd d:\home\name\addon\ & cfx run"
The outer quotes around the /C command are removed prior to execution, leaving only the quotes around your exe path. You can read about how CMD process quotes in the help. Simply type CMD /?
or HELP CMD
from a command prompt. It does get confusing.
If /C or /K is specified, then the remainder of the command line after
the switch is processed as a command line, where the following logic is
used to process quote (") characters:
1. If all of the following conditions are met, then quote characters
on the command line are preserved:
- no /S switch
- exactly two quote characters
- no special characters between the two quote characters,
where special is one of: &<>()@^|
- there are one or more whitespace characters between the
two quote characters
- the string between the two quote characters is the name
of an executable file.
2. Otherwise, old behavior is to see if the first character is
a quote character and if so, strip the leading character and
remove the last quote character on the command line, preserving
any text after the last quote character.
Your command has more than 2 quotes, so option 2 is followed.
The only time the above won't work is if your exe name contains a special character like &
, for example this&that.exe
. That causes a problem because the exe name is not quoted when the START command is initially parsed. That can be fixed by escaping the problem character within the file name.
start cmd.exe /k ""this^&that.exe" & echo something else"
Upvotes: 18
Reputation: 881
You can try with the old DOS-writing style, where every path-segment has maximal 8 chars like:
C:\Progra~1\Mozill~1\
the ~1 is from the alphabetical order:
C:\DisIsMyDirAlpha
C:\DisIsMyDirBeta
C:\DisIsMyDirGamma
are these:
C:\DisIsM~1
C:\DisIsM~2
C:\DisIsM~3
Upvotes: 4