set /p not working perhaps

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
brainuee
Posts: 1
Joined: 08 Jul 2013 10:45

set /p not working perhaps

#1 Post by brainuee » 08 Jul 2013 10:51

setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in (temp.txt) do (
set /a k+=1
set N[!k!]=%%a
)
rem set N
rem if '%N[1]%'=='' set N1=%N[1]%
set N1=%N[1]%
set N2=%N[2]%
set N3=%N[3]%
set N4=%N[4]%



pause
rem endlocal


if "%N1%"=="" set /p M1 = "give first no "
rem set m1=!M1!
rem set m1= %!M1!%
echo %M1%
setLocal EnableDelayedExpansion
if "%N2%"=="" set /p M2 = "give second no "
echo %M2%
setLocal EnableDelayedExpansion
if "%N3%"=="" set /p M3 = "give 3rd no "

echo %N4%



...........

in above code, echo %M1% and echo %M2% results to "echo is ON" instead of user input. Why this is happening?

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: set /p not working perhaps

#2 Post by penpen » 08 Jul 2013 11:15

brainuee wrote:set /p M1 = "give first no "

The set instruction works as intended.
You just are not using the variabble you expect: Your variable contains a Space at the end (in quotes: you are using "M1 " instead of "M1").

So this seems to be what you want:

Code: Select all

set /p M1= "give first no "

penpen

Edit: M2 analogous.

Post Reply