参数未在SVN批处理脚本中替换

时间:2013-10-13 16:23:59

标签: batch-file

我正在尝试自动化构建过程,但是我遇到了一个脚本参数问题。

我存储参数,然后在命令行上调用svn checkout %repository%时替换它的值。

问题是它无法替代,我得到以下输出:

PS C:\Users\Administrator\Desktop> .\Build_Script.bat "https://mitchellt/svn/Test_Repositry/Test_Application"

C:\Users\Administrator\Desktop>rem * Need to check directory exists

C:\Users\Administrator\Desktop>rem Variables

C:\Users\Administrator\Desktop>set date=13_10_2013

C:\Users\Administrator\Desktop>set time=16-56-48

C:\Users\Administrator\Desktop>set repository = https://mitchellt/svn/Test_Repositry/Test_Application

C:\Users\Administrator\Desktop>rem Change to build directory

C:\Users\Administrator\Desktop>cd C:\Build

C:\Build>rem Make Directory for Build based on today's date

C:\Build>mkdir 13_10_2013_16-56-48

C:\Build>rem Change to new directory

C:\Build>cd 13_10_2013_16-56-48

C:\Build\13_10_2013_16-56-48>rem Create folders for the source code, built product & test results

C:\Build\13_10_2013_16-56-48>mkdir Source

C:\Build\13_10_2013_16-56-48>mkdir Product

C:\Build\13_10_2013_16-56-48>mkdir Results

C:\Build\13_10_2013_16-56-48>rem Change to source directory

C:\Build\13_10_2013_16-56-48>cd Source

C:\Build\13_10_2013_16-56-48\Source>rem Copy the source code from the repository

C:\Build\13_10_2013_16-56-48\Source>svn checkout
svn: E205001: Try 'svn help checkout' for more information
svn: E205001: Not enough arguments provided
PS C:\Users\Administrator\Desktop>

CODE:

@ECHO ON
@SETLOCAL
rem * Need to check directory exists

rem Variables
set date=%DATE:/=_%
set time=%time:~0,2%-%time:~3,2%-%time:~6,2%
set repository = %1

rem Change to build directory
cd C:\Build

rem Make Directory for Build based on today's date
mkdir %date%_%time%

rem Change to new directory
cd %date%_%time%

rem Create folders for the source code, built product & test results
mkdir Source
mkdir Product
mkdir Results

rem Change to source directory
cd Source

rem Copy the source code from the repository
svn checkout %repository%

1 个答案:

答案 0 :(得分:5)

问题是set repository = %1处的空格,批处理文件对空间敏感(有时仅在某些点) 这将创建一个名为repository<space>

的变量

只需将其更改为

即可
set repository=%1

或更好

set "repository=%~1"

因为这也可以防止%1

之后附加的不可见空格出现问题