Solved

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

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Robocopy syntax 10 91
Windows task scheduler for Robocopy 3 110
Help on writing a script for check ndf file size 2 76
Vbscript 8 65
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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

17 Experts available now in Live!

Get 1:1 Help Now