Search code examples
batch-filevariablescall

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.


Solution

  • 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