if statement - Nested If-Else in batch command -
i trying check if 2 services present or not. if either 1 not present should print "no" else print "yes". tried is:
@echo off set service1=present_service set service2=not_present sc query %service1% | find "does not exist" >nul if %errorlevel% equ 1 ( sc query %service2% | find "does not exist" >nul if %errorlevel% equ 1 ( echo yes ) else ( echo no ) ) else ( echo no )
if check single one, works fine. here %errorlevel%
not changing value in second case. if service2
not present, prints yes
. can on this.
try this;
@echo off setlocal enabledelayedexpansion set service1=present_service set service2=not_present sc query %service1% | find "does not exist" >nul if %errorlevel% equ 1 ( sc query !service2! | find "does not exist" >nul if !errorlevel! equ 1 ( echo yes ) else ( echo no ) ) else ( echo no )
this problem delayed expansion
Comments
Post a Comment