[英]svn head revision from a remote repository in windows batch file - the system cannot find the file specified
How do I get a SVN revision number of a remote repository in a windows batch file ? 如何在Windows批处理文件中获取远程存储库的SVN版本号? I want to check for a condition when the user enters blank i have to get HEAD revision.
我想检查条件,当用户输入空白时,我必须获得HEAD修订版。
I'm using the following snippet to get the revision number. 我正在使用以下代码段获取修订号。 Although the for loop returns all the necessary information wrt remote SVN server location including the revision number.
尽管for循环返回有关远程SVN服务器位置的所有必要信息,包括修订号。 Still the batch file throws The system cannot find the file specified and the variable %SVN_VERSION% still remains empty.
批处理文件仍然抛出系统无法找到指定的文件 ,并且变量%SVN_VERSION%仍然为空。
In the below mentioned code, the %SVN_PATH% points to the remote server URL 在下面提到的代码中,%SVN_PATH%指向远程服务器URL
set /p "SVN_VERSION=Please specify the SVN Revision number. For HEAD revision press Enter"
if "%SVN_VERSION%" =="" (
for /f "delims=: tokens=1,2" %%a in ('svn info %SVN_PATH%') do (
if "%%a"=="Revision:" (
set /a SVN_VERSION=%%b
)
)
)
Thanks 谢谢
As I mentioned in the comments, you can directly obtain revision with svnversion command
. 正如我在评论中提到的那样,您可以使用
svnversion command
直接获得修订。
@echo off
set /p "SVN_VERSION=Please specify the SVN Revision number. For HEAD revision press Enter"
if "%SVN_VERSION%"=="" (
for /f %%a in ('svnversion') do set "SVN_VERSION=%%a"
)
exit /b 0
Edit 编辑
Here it is well explained how to use the command svnversion
在这里很好地解释了如何使用命令
svnversion
Edit 编辑
According to your comments and trying to guess in your mind, the following command should work if you know the remote_url 根据您的评论并尝试猜测,如果您知道remote_url,以下命令应该可以使用
@echo off
rem Edit remote_url
set /p "remote_url=Please specify the SVN repo url http://....." || goto:EOF
set /p "SVN_VERSION=Please specify the SVN Revision number. For HEAD revision press Enter"
if "%SVN_VERSION%"=="" (
for /f "delims=: tokens=1,2" %%a in ('svn info %remote_url%') do (
if "%%a"=="Revision" ( set SVN_VERSION=%%b )
)
)
exit /b 0
Edit 编辑
This should also work since I have seen what should be the input 这也应该起作用,因为我已经看到了输入内容
@echo off
set /p "SVN_VERSION=Please specify the SVN Revision number. For HEAD revision press Enter"
if "%SVN_VERSION%"=="" (
for /f "tokens=1,2" %%a in ('svn info %SVN_PATH% ^|findstr /ic:"Revision"') do set SVN_VERSION=%%b
)
exit /b 0
Explanation: 说明:
Your mistake was with delims=:
since :
is not part of the tokens
the comparison came wrong. 您的错误是与
delims=:
在一起的,因为:
不是tokens
的一部分,所以比较出错。 Also, the default delims
is space, so don't need to specify a delims here since the line are splited in two parts. 另外,默认的
delims
是空格,因此这里不需要指定delims,因为该行分为两部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.