我有一个批处理脚本来为我的Subversion备份运行hotcopy。像这样:
SET REPOS=D:\Repos
SET BACKUP=C:\Backup
FOR /f %%s IN('DIR /b /a:d %REPOS%') DO (
svnadmin hotcopy %REPOS%\%%s %BACKUP%\%%s
)
我想添加条件检查,以便在存储库发生更改时仅运行hotcopy。像这样的伪代码:
if (svnlook youngest repo1 != svnlook youngest backup1) {
//do hotcopy as above
}
如何在批处理脚本中实现此功能?即如何比较批处理脚本中两个命令的输出?
答案 0 :(得分:2)
未经过测试(我没有环境可以做到这一点),但这是骨架
@echo off
setlocal enableextensions enabledelayedexpansion
set "REPOS=D:\Repos"
set "BACKUP=C:\Backup"
for /d %%r in ("%REPOS%") do (
set "sourceVersion="
for /f %%a in ('svnlook youngest "%%~fr"') do set "sourceVersion=%%a"
set "targetVersion="
for /f %%a in ('svnlook youngest "%BACKUP%\%%~nxr"') do set "targetVersion=%%a"
if not "!sourceVersion!"=="!targetVersion!" (
svnadmin hotcopy "%%~fr" "%BACKUP%\%%~nxr"
)
)