To get it running at all, I had to add some setlocal
statements and add extra blank line between set lf=^
and the for
. Once I did that, I actually see different output than you:
!results!!lf!%a
[WARNING] a
[WARNING] c
This can easily be fix to work on my (Win7) machine by simply adding the following before the for
:
set results=
There will be a leading blank line in the output, but it surely be surprised by adding a conditional when data is added to results
.
But given the difference in the output you get, I guess we'll need to take a different approach to get it working for you. This should be much more robust than playing with newlines anyway.
@echo off
setlocal
setlocal EnableDelayedExpansion
set showed_header=0
for /f "delims=" %%a in ('call mvn dependency:analyze ^| findstr "WARNING"') do (
if !showed_header!==0 (
set showed_header=1
echo ------------------------------------
echo FOUND MATCHES
echo ------------------------------------
)
echo %%a
)
if %showed_header%==1 (
echo ------------------------------------
echo ------------------------------------
echo.
echo.
)
Tested using perl -e"print qq{[WARNING] a\nb\n[WARNING] c\n}"
.