Variable check in a DOS batch script does not work

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
brh56
Posts: 8
Joined: 29 Apr 2015 08:59

Variable check in a DOS batch script does not work

#1 Post by brh56 » 15 Jan 2016 09:45

Good day all.

For some unknown reason, if I omitt the hostname, it does not echo the message and go back to start.

Code: Select all

:start
cls
set host=

echo.
set /p host=   Enter the Hostname: 

if "%host%"=="" echo Please enter a valid host. & timeout 3 & goto start


Any ideas?

Regards,

Bjoern

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Variable check in a DOS batch script does not work

#2 Post by Squashman » 15 Jan 2016 10:37

I copied and pasted your exact code into a batch file and it works as it is intended to.

brh56
Posts: 8
Joined: 29 Apr 2015 08:59

Re: Variable check in a DOS batch script does not work

#3 Post by brh56 » 15 Jan 2016 11:00

Squashman wrote:I copied and pasted your exact code into a batch file and it works as it is intended to.

Which version are you running?

Code: Select all

C:\>ver

Microsoft Windows [Version 6.1.7601]

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Variable check in a DOS batch script does not work

#4 Post by Squashman » 15 Jan 2016 11:08

I tested on Windows 7 Pro, Windows 2008 Server, Windows 2012 Server and will test on XP Pro as soon as I get the VM reinstalled on my new laptop.

brh56
Posts: 8
Joined: 29 Apr 2015 08:59

Re: Variable check in a DOS batch script does not work

#5 Post by brh56 » 15 Jan 2016 11:15

Ok, stand down, I found found the problem. I had another line before the check.

Thanks for your responses.

Bjoern

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Variable check in a DOS batch script does not work

#6 Post by Squashman » 15 Jan 2016 20:52

Yes. Hard for us to help when you only provide a code snippet or obfuscate your code examples.

Post Reply