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?
When you send arguments, those with poison or space characters need to be doublequoted. Inside your batch file, if you no longer need the surrounding doublequotes, you'd remove them by using %~5 instead of %5 . Additionally the recommended syntax for the set command is Set "VariableName=VariableValue" .
Example# @echo off prevents the prompt and contents of the batch file from being displayed, so that only the output is visible. The @ makes the output of the echo off command hidden as well.
Use quotation marks when specifying long filenames or paths with spaces. For example, typing the copy c:\my file name d:\my new file name command at the command prompt results in the following error message: The system cannot find the file specified. The quotation marks must be used.
The Windows command-line interpreter uses a caret character ( ^ ) to escape reserved characters that have special meanings (in particular: & , | , ( , ) , < , > , ^ ).
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"
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With