批处理脚本存储在一个变量的某些细节输出 [英] Batch script to store certain output details in a Variable

查看:137
本文介绍了批处理脚本存储在一个变量的某些细节输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Could someone help me in this Batch script.

我需要SVN信息运行下面的命令,并在一个变量来获得某些细节。

I need to run the below command svn info and to get certain details in a variable.

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)

,我在我的脚本创建一些临时文件。在脚本的末尾,我需要找到任何有效的文件,应该将其删除。

And i'm creating some temp files in my script. at the end of script i need to find any available files and should delete it.

推荐答案

甚至可能更容易UNIX的工具,而是纯粹的批次没有很大的挑战(保持它不优化简单):

probably even easier with unix-tools, but no big challenge with pure batch (kept it simple without optimizations):

@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 

这篇关于批处理脚本存储在一个变量的某些细节输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆