Terminal Escape Sequence and next line position
Posted: 22 Sep 2021 13:21
Like many of us, I have used the technique I have scene from Jeb and others to generate a new line using a carrot and two blank lines and this works great in an example like this:
I was testing using the Terminal Escape sequence for the next line with ESC[E (https://docs.microsoft.com/en-us/window ... -sequences). This works great if I were to echo to the console:
However, this does not work when echoing to a file. I suspect the Terminal Escape Sequence only applies to the output to the cursor position on the console. Is there a workaround or is it best to just continue using the LF=^ method? I have no problem using the tried and true, but it is always interesting to find new methods.
Code: Select all
@echo off
setlocal enabledelayedexpansion
set LF=^
:: The two empty lines are required here
set "usbInfo="
for /f "skip=1 tokens=*" %%i in ('wmic path win32_pnpentity where "Present='True' AND PNPClass='USB'" get Name') do for /f "tokens=*" %%j in ("%%i") do (
set "usbInfo=!usbInfo!!LF!"
set "usbInfo=!usbInfo!%%j"
)
echo !usbInfo!>"%userprofile%\test.txt"
Code: Select all
for /f %%g in ('echo prompt $E^| cmd') do set "LF=%%g[E"
echo !usbInfo!