繁体   English   中英

批处理脚本可将某些输出详细信息存储在变量中

[英]Batch script to store certain output details in a Variable

有人可以帮我这个批处理脚本。

我需要运行以下命令svn info并在变量中获取某些详细信息。

Path: .
Working Copy Root Path: C:\Users\jslevin\Desktop\SQL
URL: https://ofss220383.in.oracle.com:18080/svn/SVN_DEMO/branches/FCUBS_TEST/Soft/AM/SQL
Relative URL: ^/branches/FCUBS_TEST/Soft/AM/SQL
Repository Root: https://ofss220383.in.oracle.com:18080/svn/SVN_DEMO
Repository UUID: 866b0b85-a196-4771-a359-d37e344426b2
Revision: 47
Node Kind: directory
Schedule: normal
Last Changed Author: john.levin@oracle.com
Last Changed Rev: 47
Last Changed Date: 2016-04-11 18:01:56 +0530 (Mon, 11 Apr 2016)

Var1 = SVN_DEMO (This variable should hold the Repository Root: line and should get the Last word i.e., SVN_DEMO)

Var2 = FCUBS_TEST (Should grep URL: and hold the word after branches alone i.e., FCUBS_TEST)

而且我正在脚本中创建一些临时文件。 在脚本末尾,我需要找到任何可用的文件并将其删除。

使用unix-tools可能更容易,但是使用纯批处理就没有太大的挑战(无需优化就可以保持简单):

@echo off
REM get the two important lines into variables:
for /f "tokens=*" %%a in ('find "Repository Root" file.txt') do set var1=%%a
for /f "tokens=*" %%a in ('find "Relative URL" file.txt') do set var2=%%a

:loop
REM var1 - remove from the beginning until (including) the first '/':
set var1=%var1:*/=%
REM if there is another '/' then do it again:
if "%var1%" neq "%var1:/=%" goto :loop
REM kind of "brute force", isn't it?

REM var2: remove from the beginning until (including) 'branches/':
set var2=%var2:*branches/=%
REM take the first token by '/' as delimiter:
for /f "delims=/" %%a in ("%var2%") do set var2=%%a

set var 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM