Kai Lutsaffe
Kai Lutsaffe

Reputation: 13

Issue with my code echoing "OFF" despite no reason for it to do so, to my knowledge

I have some code in batch for taking in user input, and outputting the inputed info using echo, yet it only outputs "ECHO is OFF".

I've copy and pasted the small tidbit of code into its own program and have figured out that is revolves around this specific bit of code. I've spent the last few days sparsely in my free-time trying to figure out why this isn't working, and I'd love to post the full programs worth of code, but its a tad confidential right now. I've simplified the code into a functional "program" so you guys can just copy and paste to test it yourself, but I'm having issues with it and have no idea why.

@echo off

SETLOCAL EnableDelayedExpansion
set /p "%UserMSGInput%= >"
echo %UserMSGInput%
pause

I'm expecting it to simply output the user input value, but instead it just outputs 'ECHO IS OFF'.

Upvotes: 1

Views: 41

Answers (1)

Steve
Steve

Reputation: 716

I believe what you're trying to do is:

set /p UserMSGInput=" >"

The line:

set /p "%UserMSGInput%= >"

means "prompt for input, using the value of the environment variable UserMSGInput as part of the prompt." But there's no environment variable name in that command.

Since %UserMSGInput% doesn't have a value, the prompt becomes just ">". The echo command is trying to print an environment variable that doesn't exist, so it just sees:

echo

which means "print the current state of the echo command" - in this case, "ECHO is off."

Upvotes: 1

Related Questions