i am writing a batch script file (.bat) where i need to decode a base64 (Base64 utility for Windows) text and them encode to hex. I can do this. The problem is that i need to store the result in a variable.
For example:
I execute this in cmd:
base64 -d -s ZGG01YZq3ZJLbK3Cz1nOhA | hexdump
The result print to standard output is:
000000 64 61 b4 d5 86 6a dd 92 4b 6c ad c2 cf 59 ce 84
000010 01 b4 d5 86 6a dd 92 4b 6c ad c2 cf 59 ce
I need to store only the first line without any space and without the prefix 000000. To be clear, i need to store 6461b4d5866add924b6cadc2cf59ce84 in the variable readValue1.
Im triying with this code in the .bat file, but its crash:
call :decodefunction
:decodefunction
SETLOCAL ENABLEDELAYEDEXPANSION
SET count=1
for /f "delims=" %%a IN ('base64 -d -s ZGG01YZq3ZJLbK3Cz1nOhA | hexdump') DO (
SET readValue!count!=%%a
SET /a count=!count!+1
)
ECHO %readValue1%
ECHO %readValue2%
ENDLOCAL
This code does what you requested:
:decodefunction
SETLOCAL ENABLEDELAYEDEXPANSION
for /f "tokens=1*" %%a IN ('base64 -d -s ZGG01YZq3ZJLbK3Cz1nOhA ^| hexdump') DO (
SET "readValue1=%%b"
GOTO break
)
:break
SET "readValue1=%readValue1: =%"
ECHO %readValue1%
ENDLOCAL