San Jay Falcon
San Jay Falcon

Reputation: 1013

Batch file: store output function call in var

This doesn't seem to be that hard, however, can't seem to get the output of a function call stuffed into a variable.

SET info=
call git log -6
REM echo %info%
echo { "timestamp": "%time% %date%", "info": "%info%" } >> ".\src\assets\build-info.json"

Some or a pointer in the right direction would be appreciated meaning.

Upvotes: 0

Views: 176

Answers (1)

Amnon
Amnon

Reputation: 2320

I suggest to have your command output a more easily parseable output, and send it to a file.

You could then use for /f to read a the file line by line (even tokenize the lines) into a variable, then write the variable to a file.

for example:

git log --format="%aI | %an | %s" > git.log
(for /f "delims=| tokens=1-3" %a in (git.log) do @echo {"timestamp":"%a", "info":"%c"}) > git.log.json

Upvotes: 1

Related Questions