How can I use spaces in the Windows Command Line?
cmd /C C:\Program Files (x86)\WinRar\Rar.exe a D:\Hello 2\File.rar D:\Hello 2\*.*
How can I use spaces in the Windows Command Line?
cmd /C C:\Program Files (x86)\WinRar\Rar.exe a D:\Hello 2\File.rar D:\Hello 2\*.*
Single quotation marks won't do in that case. You have to add quotation marks around each path and also enclose the whole command in quotation marks:
cmd /C ""C:\Program Files (x86)\WinRar\Rar.exe" a "D:\Hello 2\File.rar" "D:\Hello 2\*.*""
See also the cmd.exe remarks section.
cmd /C
–
Carolecarolee CEEMEA & LATAM.doc
. What should I do? "C:\Program Files\WinRAR\rar" a -agmmddyy -x*CEEMEA & LATAM.doc ".rar"
–
Intendant I just figured out that for a case where the path involves the use of white space characters, for example, when I need to access the app xyz
which location is :
C:\Program Files\ab cd\xyz.exe
To run this from windows cmd prompt, you need to use
C:\"Program Files"\"ab cd"\xyz.exe
or
"C:\Program Files\ab cd\xyz.exe"
os
python library and run all scripts in cmd by python one by one. write all path files (must use /
as shown as bellow ) in a list and with for
run them one by one . Like os.system( 'python "C:/Program Files (x86)/Jenkins/workspace\Map Checker Unit Test/sqs-poller/node_modules/map-checker/python/unit_test.py"' )
–
Lazarus If double quotes do not solve the issue then try e.g.
dir /X ~1 c:\
to get a list of alternative file or directory names. Example output:
11/09/2014 12:54 AM 8,065 DEFAUL~1.XML Default Desktop Policy.xml
06/12/2014 03:49 PM <DIR> PROGRA~1 Program Files
10/12/2014 12:46 AM <DIR> PROGRA~2 Program Files (x86)
Now use the short 8 character file or folder name in the 5th column, e.g. PROGRA~1 or DEFAUL~1.XML, in your commands. For instance:
set JAVA_HOME=c:\PROGRA~1\Java\jdk1.6.0_45
I prefer to enclose the command in ()
which is valid batch
which makes it a bit easier to read:
cmd /C ("C:\Program Files (x86)\WinRar\Rar.exe" a "D:\Hello 2\File.rar" "D:\Hello 2\*.*")
Try to provide complex pathnames in double-quotes (and include file extensions at the end for files.)
For files:
call "C:\example file.exe"
For Directory:
cd "C:\Users\User Name\New Folder"
CMD interprets text with double quotes ("xyz") as one string and text within single quotes ('xyz') as a command. For example:
FOR %%A in ('dir /b /s *.txt') do ('command')
FOR %%A in ('dir /b /s *.txt') do (echo "%%A")
And one good thing, cmd is not* case sensitive like bash. So "New fiLE.txt" and "new file.TXT" is alike to it.
*Note: The %%A variables in above case is case-sensitive (%%A not equal to %%a).
Enclose the paths containing spaces with double quotes.
cmd /C "C:\Program Files (x86)\WinRar\Rar.exe" a "D:\Hello 2\File.rar" "D:\Hello 2\*.*"
Rar.exe
actually is. You might be using it wrongly. Maybe try "D:\Hello 2\"
or "D:\Hello 2"
instead of "D:\Hello 2\*.*"
? –
Sibel CEEMEA & LATAM.doc
. What should it be? "C:\Program Files\WinRAR\rar" a -x*CEEMEA & LATAM.doc ".rar"
–
Intendant set "CMD=C:\Program Files (x86)\PDFtk\bin\pdftk"
echo cmd /K ""%CMD%" %D% output trimmed.pdf"
start cmd /K ""%CMD%" %D% output trimmed.pdf"
this worked for me in a batch file
Spaces in the Commend Prompt (in a VBA Shell command code line)
I had a very similar problem which ended up being a space in the command prompt when automating via VBA to get the contents from the command window into a text file. This Thread was one of many I caught along the way that didn’t quite get me the solution.
So this may help others with a similar problem: Since the syntax with quotes is always difficult to get right , I think showing some specific examples is always useful. The additional problem you get using the command prompt in VBA via the Shell thing, is that the code line often won’t error when something goes wrong: in fact a blink of the black commend window misleads into thinking something was done.
As example… say I have a Folder, with a text file in it like at
C:\Alans Folder\test1.txt ( https://i.stack.imgur.com/UiCVF.jpg )
The space there in the folder name gives the problem.
Something like this would work, assuming the Folder, AlansFolder, exists
Sub ShellBlackCommandPromptWindowAutomatingCopyingWindowContent()
Shell "cmd.exe /c ""ipconfig /all > C:\AlansFolder\test1.txt"""
End Sub
This won’t work. (It won’t error).
Sub ShellBlackCommandPromptWindowAutomatingCopyingWindowContent()
Shell "cmd.exe /c ""ipconfig /all > C:\Alans Folder\test1.txt"""
End Sub
Including quote pairs around the path will make it work
Sub ShellBlackCommandPromptWindowAutomatingCopyingWindowContent()
Shell "cmd.exe /c ""ipconfig /all > ""C:\Alans Folder\test1.txt"""""
End Sub
( By the way, if the text file does not exist, then it will be made).
With the benefit of hindsight, we can see that my solution does tie up approximately with some already given..
Converting that code line to a manual given command we would have
ipconfig /all > "C:\Alans Folder\test1.txt"
That seems to work
This works also
ipconfig /all > C:\AlansFolder\test1.txt
This doesn’t
ipconfig /all > C:\Alans Folder\test1.txt
This final form also works and ties up with the solution from sacra ….” You have to add quotation marks around each path and also enclose the whole command in quotation marks “ …..
cmd.exe /c "ipconfig /all > "C:\Alans Folder\test1.txt""
Just add Quotation Mark
Example:"C:\Users\User Name"
Hope it got Solved!
You should try using quotes.
cmd /C "C:\Program Files (x86)\WinRar\Rar.exe" a "D:\Hello 2\File.rar" "D:\Hello 2\*.*"
It can solve this problem by cd command, this command understand spaces without double quotes and you can call any program this way for example:
C:\Windows\system32>cd c:\Program Files\MongoDB\Server\3.2\bin
c:\Program Files\MongoDB\Server\3.2\bin>mongo now command prompt call mongo.exe
© 2022 - 2024 — McMap. All rights reserved.