Blank input on Set /P not being handled in IF / Then in BAT file

Hello,

I have an IF statement that needs to handle an event when the user hits ENTER instead of typing input.  I thought i had it working, but it doesn't seem to get where it needs to go if the user enters nothing.  If a user actually enters an IP here, it gets set, but if they just hit enter, I want to keep it as default (set above) and instead it gets set to nothing....please help.
SET FTPHOST=192.168.0.1
set /P sel2=Enter your XBMC IP Address [%FTPHOST%]:
   if "%sel2" == "" goto else1
     SET FTPHOST=%sel2%
   goto endif1
   :else1
     echo got here
     goto :_setun
   :endif1

Open in new window

electricd7Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
SteveGTRConnect With a Mentor Commented:
On your last question I'd missed what the other expert has pointed out.

if "%sel2" == "" goto else1

Should be:

if "%sel2%" == "" goto else1
0
 
electricd7Author Commented:
heh..ok..guess i should have read the responses better too :) Let me try it out.
0
 
electricd7Author Commented:
yep..that was it...here's another 500 for you :)
0
 
SteveGTRCommented:
I'm going to add a comment to the other question for the other expert to submit a comment here. That way you can accept their answer and give them full points as it was their original idea.
0
 
SteveGTRCommented:
Oh well, I'll gladly accept the 500 points. But, I'll show you the else construct:

SET FTPHOST=192.168.0.1
set /P sel2=Enter your XBMC IP Address [%FTPHOST%]:

if "%sel2%" == ""  (
  echo got here
) else (
  SET FTPHOST=%sel2%
)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.