Reputation: 676
Scenario
I want that If user enters a value, I get host name and If user do not enter any value then I just echo default path.
Problem Statement
After adding these conditions in if else I am getting echo is off if user enters a values.
How can i resolve this?
SET /P USER_INSTALL= Installation Path :
@echo:
if "%USER_INSTALL%"=="" ( echo "------Default path------") else (
ECHO %USER_INSTALL%
FOR /F "usebackq" %%i IN (`hostname`) DO SET HOST=%%i
ECHO %HOST%)
Upvotes: 0
Views: 612
Reputation: 504
I am not sure I fully understand what you are trying to do, but try this:
@echo off
SET /P USER_INSTALL=Installation Path :
if "%USER_INSTALL%"=="" goto IP1
goto :IP2
:IP1
echo "------Default path------"
PAUSE
exit
:IP2
ECHO %USER_INSTALL%
FOR /F "usebackq" %%i IN (`hostname`) DO SET HOST=%%i
ECHO %HOST%
PAUSE
exit
This organizes the code a bit. I added pause commands so you can see what it is doing. When testing this, I am not getting an "echo is off" error. Please let me know if it works!
Upvotes: 1