如何使用包含空格的参数从另一个批处理文件调用一个批处理文件?
我有 2 层(将来可能会更多)批处理文件,这让我的生活变得更轻松,直到我尝试添加其中包含空格的路径。
批处理文件 1:
@echo off
set thinga=c:\final build
set thingb=\\server\deployment for final buil
echo.
echo thing a: %thinga%
echo thing b: %thingb%
echo.
call lala.bat "%thinga%" "%thingb%"
批处理文件 2 (lala.bat):
@echo off
echo.
echo. Param 1 %1
echo. Param 2 %2
echo.
set BASE=%1
set TARGET=%2
echo. Want to run:
echo. doSomethingOnBaseFolder %BASE%
echo. doSomethingOnBaseSubFolder "%BASE%\bin\release\*" "%TARGET%\"
echo.
其输出为:
doSomethingOnBaseSubFolder ""c:\final build"\bin\release\*" ""\\server\deployment for final buil"\"
但我希望输出为 没有
doSomethingOnBaseSubFolder "c:\final build\bin\release\*" "\\server\deployment for final buil\"
办法以其他方式转义空格吗?
I have 2 (maybe more in future) layers of batch files that are making my life easier up until the point I tried to add paths with spaces in them.
Batch file 1:
@echo off
set thinga=c:\final build
set thingb=\\server\deployment for final buil
echo.
echo thing a: %thinga%
echo thing b: %thingb%
echo.
call lala.bat "%thinga%" "%thingb%"
Batch file 2 (lala.bat):
@echo off
echo.
echo. Param 1 %1
echo. Param 2 %2
echo.
set BASE=%1
set TARGET=%2
echo. Want to run:
echo. doSomethingOnBaseFolder %BASE%
echo. doSomethingOnBaseSubFolder "%BASE%\bin\release\*" "%TARGET%\"
echo.
The output of this is:
doSomethingOnBaseSubFolder ""c:\final build"\bin\release\*" ""\\server\deployment for final buil"\"
But I want the output to be
doSomethingOnBaseSubFolder "c:\final build\bin\release\*" "\\server\deployment for final buil\"
Is there no way to escape the space in any other way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用以下语法:
%~1 是第一个不带引号的参数,然后在其周围加上引号以正确处理其中包含空格的路径。这样你就永远处于安全的一边。
Use this syntax:
The %~1 is the first parameter without quotes, then put quotes around it to correctly handle paths with spaces in them. Like that you are always on the safe side.