I have a command called compare which returns a number. I want to print some spaces and then "text" then the number to a file. Expected output is like:
text1
My code prints text1
with no spaces
set "output= text"
<nul set /p "=!output!" >> "%resultFile%"
compare -metric NCC "a.jpg" "b.jpg" "c.jpg" 2>> "%resultFile%"
I tried to print a tab character echo <TAB> >> "%resultFile%"
but it gave me an error ">> was unexpected at this time." What should I do? Thanks in advance!
This works well:
set "output= text"
>> "%resultFile%" echo %output%
So what about appending the command output in 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 https://stackoverflow.com/a/2340018/711006. I’d prefer the for
option but it does not work for the error output.
EDIT
The OP suggested editing the last line to this:
echo !output!!number! >> "%resultFile%"
The !
’s instead of %
’s are needed when the commands are expanded together, for example as a part of an if
or for
block. However, one has to issue the command setlocal EnableDelayedExpansion
before and we have not mentioned this in this question.
And I would recommend further reading about swapping the command and output redirection: Problems with an extra space when redirecting variables into a text file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With