Solved

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

Posted on 2007-12-04
5
471 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:electricd7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 30

Accepted Solution

by:
SteveGTR earned 500 total points
ID: 20406672
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
 

Author Comment

by:electricd7
ID: 20406679
heh..ok..guess i should have read the responses better too :) Let me try it out.
0
 

Author Comment

by:electricd7
ID: 20406696
yep..that was it...here's another 500 for you :)
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 20406697
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
 
LVL 30

Expert Comment

by:SteveGTR
ID: 20406723
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

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question