0

This is the code I'm trying to test. I rounded up that this wouldn't work because When I enter a string, it doesn't output the variable when I echo it (with or without the quotes). I'm just using Notepad++ to write this in, and I'm running it on Windows 8.1.

@ECHO OFF

set /p name = Enter a name:
echo "%name%"

pause
exit

Exact output when I type in 'Bob':

Enter a name:Bob
""
Press any key to continue . . .
0

4 Answers 4

2

with set /p name =..., you are defining a variable %name %, not %name%.

Sign up to request clarification or add additional context in comments.

Comments

0

Try typing set /?. Why wouldn't you have done that.

 SET /P variable=[promptString]

All your command does is write what you type

You probably have spaces in the set command. set /p name=whatever

4 Comments

I did try that, but it didn't give me what I wanted. Look at the output that is produced, I added it. I know it's a simple program, but that's just because I'm testing one feature.
You don't seem to pay attention when people tell you things. You assume you know what they are saying when you don't.
What does that have to do with Batch or coding in general?
We keep telling you but you won't listen. You didn't define a variable name (your answer was "I did try that"). Now you are using the wrong variable name.
0

This should work for you:

@echo off

set /p name=Enter a name:
echo "%name%"

pause
exit

Exact output when I type in 'Bob':

Enter a name:Bob
"Bob"
Press any key to continue . . .

7 Comments

Whoops, I did have a variable stored into it, name. I just forgot to add that part when I typed it in on the question. It still doesn't work.
@Twonty2 You sure it doesn't work? for me it works fine.
Yeah, I copied your code directly and the same thing happened. I don't know what I'm doing wrong. What did you write the code in?
My file name is test.bat
Yeah, same. I don't know. It's worked before, it's just not working now.
|
0

I had the same problem and was looking for an answer under posts like this one so i'm going to put this here in case it helps anyone.

I had this exact same issue of the variable not containing anything, and I fixed it by adding SETLOCAL ENABLEDELAYEDEXPANSION at the top of the script. My SET /P was inside an IF statement, and they can interact in a weird way. If you do this, you can access your SET /P VARIABLE=... with !VARIABLE! instead of %VARIABLE%.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.