Solved

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

Posted on 2007-12-04
5
468 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
  • 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB Script / Windows Batch: open simultaneously remote desktop connections 6 42
Edit Registry Key via Batch File 8 62
batch script 3 37
Batch Files - Error Handling 4 24
The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now