Pass a path with space to a batch file as a parameter
60,942
To pass parameters with spaces you need to quote the parameter, then you can remove the quotes using %~1
.
So the full script would look like
SET var5=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64\
CALL scripts\vc64.bat "%var5%"
SET var6=%~1vcvarsx86_amd64.bat
CALL %var6%
Related videos on Youtube
Author by
user565739
Updated on September 18, 2022Comments
-
user565739 over 1 year
In first.bat, I use
var5=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64\ CALL scripts\vc64.bat %var5%
And in scripts\vc64.bat, I use
SET var6=%1vcvarsx86_amd64.bat CALL %var6%
But I get :
'C:\Programvcvarsx86_amd64.bat' is not internal or external command.....
error.If the path assigned to var5 has no space, then it is fine.
I tried several combination of quotations and
%1vcvarsx86_amd64.bat
, but no change.How do I make it works with path with spaces?
To be more precise, suppose it is C:\a b c\
In first.bat: SET var6=C:\a b c\ =====> '"C:\avcvarsx86_amd64.bat"' is not.....` SET var6="C:\a b c\" ====> There should not be a b SET var6=C:\a\ b\ c\ ====> Can't find the specified path SET var6=C:\a b c\ + Using "%var6" ====> There should not be a b
Update: Here is an example. Change a b to ab works.
call.bat in C:\
@ECHO OFF SET var5=C:\a b\ CALL C:\1.bat "%var5%" pause
1.bat in C:\
@ECHO OFF SET var6=%~1Test.bat CALL %var6% RMDIR /S C:\NoWorry
Test.bat in C:\a b Test.bat in C:\ab
@ECHO OFF RMDIR /S C:\ThereIsNoSuchFolder
-
feeela over 11 yearsHave you tried escaping the single spaces with backslashes (
bla\ blub
) or enclosing the whole path in quotes ("bla blub"
)?
-
-
user565739 over 11 yearsThis gives me
1> There should not be Files。
-
Bali C over 11 yearsIt works fine for me, I was missing a
set
in the answer, try now. -
user565739 over 11 yearsUsing "%var5" just give errors like
There should not be....
. I don't know why. -
user565739 over 11 yearsI mean use quote with %(variable name) just gives me error and it can't call vc64.bat. Without the quotes, it can call vc64.bat, but the parameter is not good.
-
Bali C over 11 yearsYou need to use
"%var5%"
with a%
sign at each side. -
user565739 over 11 yearsSorry, it is just a typo here. In the bat, no such mistake but don't work. I may just upload the file and you may see what's the problem.
-
Bali C over 11 yearsYeah sure, just edit your question and post all your scripts and I can have a look. Just put
Update
or something in the question so I know what's new :) -
Bali C over 11 yearsIt works fine for me, I get
C:\a b\Test.bat
in%var6%
, so I'm not sure why yours won't work, sorry! -
user565739 over 11 yearsNever mind, I found the answer. To make the call successful, it should be "C:\a b\Test.bat" or "C:\a b"\Test.bat
-
Arturas M over 4 yearsIt does not work. Or at least not in all cases. There are exceptions when the arguments themselves contain quotes, in that case the arguments may not have extra quotes, otherwise they get passed without quotes and your application won't work.