如何使用包含空格的参数从另一个批处理文件调用一个批处理文件?

发布于 2024-10-04 01:31:05 字数 850 浏览 0 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伪装你 2024-10-11 01:31:05

使用以下语法:

set VAR="%~1"

%~1 是第一个不带引号的参数,然后在其周围加上引号以正确处理其中包含空格的路径。这样你就永远处于安全的一边。

Use this syntax:

set VAR="%~1"

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文