I use the below function to check if echo is set on or off, and as you can see it pipes echo statuse and then uses the output to set a flag:
FUNCTION
:echos
echo > echo.txt & rem pipe ech status to a text file
@echo off
set _echos=yes
:: default assumption is that echo was on
CALL FileStringLength echo.txt & rem fetch string length. eq to 12 if off
IF %_strlength% EQU 12 (set _echos=no)
del echo.txt & rem zap temporary file
set "_strlength=" & rem zap temporary variable
set "_echos" & rem show status
IF %_echos% EQU yes (@echo on
) ELSE (
@echo off
)
:: /echos
It works fine, but creating a file feels ... inelegant. so I thought, hmmm why not just do a redirection? replace the pipe with
>echo|set /p _str="redirect"
the result is as below, and when I check the string variable it's not there:
redirect
>set _str
Environment variable _str not defined
>
not what I wanted. At some point, in the early hours when the mind wanders I got the result! Whoohoo! crashed beautificaly on the sofa ... but could not for the life of me remember what arcane combination of code got the redirect to work! sigh anyone out there who has solved this particular problem? or was it all just a hallucination brought on by ocd in the early hours?