Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

20 Experts available now in Live!

Get 1:1 Help Now