Package. Unable to print spaces. The beginning of the line.

I have a command called compare that returns a number. I want to print some spaces, then "text" and then the number in the file. The expected result is as follows:

text1 

My code prints text1 without 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 that gave me the error "→ was unexpected at this time." What should I do? Thanks in advance!

+6
source share
1 answer

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

+1
source

Source: https://habr.com/ru/post/989676/


All Articles