如何从另一个调用批处理文件批处理文件包含空格的参数呢? [英] How to call a batch file from another batch file with parameters that contain spaces?

查看:340
本文介绍了如何从另一个调用批处理文件批处理文件包含空格的参数呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个(或许更多未来)层的批处理文件,这些文件使我的生活更轻松,直到我试图加入他们空格的路径点。

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.

批处理文件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):

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.

这个输出是:

doSomethingOnBaseSubFolder ""c:\final build"\bin\release\*" ""\\server\deployment for final buil"\"

但我想输出为

doSomethingOnBaseSubFolder "c:\final build\bin\release\*" "\\server\deployment for final buil\"

有没有办法逃避任何其他方式的空间?

Is there no way to escape the space in any other way?

推荐答案

使用此语法:

set VAR="%~1"

在%〜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.

这篇关于如何从另一个调用批处理文件批处理文件包含空格的参数呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆