gpt4 book ai didi

batch-file - SVN 批处理脚本中的参数未被替换

转载 作者:行者123 更新时间:2023-12-02 21:47:02 25 4
gpt4 key购买 nike

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

我存储参数,然后在命令行上调用 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>

代码:

@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%

最佳答案

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

只需将其更改为

set repository=%1

或者更好

set "repository=%~1"

因为这也可以防止 %1 之后附加的不可见空格的问题。

关于batch-file - SVN 批处理脚本中的参数未被替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19347442/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com