@echo on
for /F "tokens=*" %%A in (temk.txt) do (set val=%%A
echo %val%
)
temk.txt内容:
<vault-option name="KEYSTORE_PASSWORD" value="MASK-2U8Xggca4VLP8Xx7nYzGE/"/>
我无法看到echo%val%的输出。请帮助我,不知道我错过了什么。
答案 0 :(得分:0)
这是一个混合代码批处理+ vbscript来提取值:
@echo off
Set "InputFile=temk.txt"
Set "OutPutFile=OutputFile.txt"
Set "Tmpvbs=%temp%\Tmpvbs.vbs"
Call :Extract "%InputFile%" "%OutPutFile%"
Setlocal enabledelayedexpansion
for /f "delims=" %%a in ('Type "%OutPutFile%"') Do (
Set "Val=%%a"
)
Echo Val = !Val! & pause>nul
Exit
::****************************************************
:Extract <InputData> <OutPutData>
(
echo Data = WScript.StdIn.ReadAll
echo Data = Extract(Data,"value=""(.*)"""^)
echo WScript.StdOut.WriteLine Data
echo Function Extract(Data,Pattern^)
echo Dim oRE,oMatches,Match,Line
echo set oRE = New RegExp
echo oRE.IgnoreCase = True
echo oRE.Global = True
echo oRE.Pattern = Pattern
echo set oMatches = oRE.Execute(Data^)
echo If not isEmpty(oMatches^) then
echo For Each Match in oMatches
echo Line = Line ^& Match.Submatches(0^)
echo Next
echo Extract = Line
echo End if
echo End Function
)>"%Tmpvbs%"
cscript /nologo "%Tmpvbs%" < "%~1" > "%~2"
If Exist "%Tmpvbs%" Del "%Tmpvbs%"
exit /b
::****************************************************