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

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

我需要运行下面的命令svn info并获取variables中的某些细节。

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 ie, SVN_DEMO) Var2 = FCUBS_TEST (Should grep URL: and hold the word after branches alone ie, FCUBS_TEST) 

而我正在我的脚本中创build一些临时文件。 在脚本的末尾,我需要find任何可用的文件,并删除它。

Solutions Collecting From Web of "批处理脚本将某些输出详细信息存储在variables中"

使用unix工具可能会更容易一些,但对纯批处理没有太大的挑战(保持简单而没有优化):

 @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