[Batch] ECHO command disabled

Solved
koma_666 Posted messages 473 Status Member -  
koma_666 Posted messages 473 Status Member -
Hello everyone,

I’m facing a problem with my code below (which should display the message "activate" if my Wi-Fi is disconnected)
When I try to display the value of my variable k, I get the message "ECHO command disabled". So, it's impossible to test my if condition that follows since I don't know the value of k.
Note that in the for command, echo %%k works fine and displays "Media disconnected".

I added some comments in the code for understanding.

Do you have any idea what the problem is?

@echo off
cls
setlocal enableDelayedExpansion

REM get the line number of *wireless Wi-Fi* from the ipconfig command

for /f "tokens=1 delims=]" %%i in ('ipconfig ^| find /N "wireless Wi-Fi"') do (
for /f "tokens=1 delims=[" %%j in ("%%i") do (
set result=%%j
echo !result!

)
)

REM increment the line number for using in skip

set /a result=result+1
echo %result%

REM read the result from line %result%

for /f "skip=%result% tokens=2 delims: " %%k in ('ipconfig') do echo %%k & goto suit
:suit

REM error here: ECHO command disabled.

echo !k!
echo %k%


pause

REM impossible to check the value of %k% because of "ECHO command disabled" error. The result of the if is always "disabled"
if ["!k!"==" Media disconnected"] (echo activate) else (echo disabled)

pause



Which gives the output:

34
35
Media disconnected
ECHO command disabled.
ECHO command disabled.
Press any key to continue...
disabled
Press any key to continue...

Configuration: Windows / Firefox 46.0

10 answers

dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   5 659
 
bonjour
essayez
for /f "skip=%result% tokens=2 delims=:" %%k in ('ipconfig') do set x=%%k&echo %%k & goto suit 
:suit

echo %x%
0