This works well:
set "output= text" >> "%resultFile%" echo %output%
How about adding command output to the batch itself?
set "output= text" call compare -metric NCC "a.jpg" "b.jpg" "c.jpg" 2> temp.txt set /p number=<temp.txt del temp.txt >> "%resultFile%" echo %output%%number%
See fooobar.com/questions/11135 / .... Id prefers the for parameter, but it does not work for error output.
EDIT
OP suggested editing the last line:
echo !output!!number! >> "%resultFile%"
! s instead of % s are needed when commands are deployed together, for example, as part of an if or for block. However, we need to bring the setlocal EnableDelayedExpansion to this, and we did not mention this in this matter.
And I would recommend reading further about replacing command redirection and output: Problems with extra space when redirecting variables to a text file
source share