![](/img/trans.png)
[英]Batch Scripting - Saving the output of systeminfo command to a variable
[英]Command output to a file with batch scripting
我正在尝试生成一个xml文件。 我使用返回数字的命令比较两个图像。 但是当我尝试将其输出重定向到文件时,它会使用换行符打印该数字。
echo a.jpg >> "result.txt"
compare -metric NCC "a.jpg" "b.jpg" "c.jpg" 2>> "result.txt"
预期输出如:
a.jpg 1
但它输出:
a.jpg
1
我试图从命令中获得结果并尝试与a.jpg连接,但我无法管理。
for /f "tokens=1 delims=" %%a in ('compare -metric NCC "a.jpg" "b.jpg" "c.jpg"') do set result=%%a
echo %result%
REM outputs 1ECHO is off.
第一个命令添加换行符。 像这样使用它来避免它并在一行中输出。
echo|set /p=a.jpg >> "result.txt"
现在我知道了,会发生什么:
compare -metric NCC "a.jpg" "b.jpg" "c.jpg" 2>> "result.txt"
您想要的输出是在STDERR上,而不是在STDOUT上(非常不寻常)。 但是仅for
捕获STDOUT。
应该可以对for
构造进行调整,但使用起来更简单:
<nul set /p "=a.jpg " >> "result.txt"
REM this line writes a string without linefeed
compare -metric NCC "a.jpg" "b.jpg" "c.jpg" 2>> "result.txt"
REM this line appends the STDERR of the "compare" command to the line
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.