How to make a conditional lable call in batch -
i want make simple batch script should able run ant build script. when start batfile want prompt me target name. simple conditional test: if type enter (without entering string) goto lable1, else goto lable2 (wich calls ant argument, have entered @ promt). tried didn't work:
@echo off set /p target=please enter target: if %target%=="" (goto call_script_with_default_target) else (goto call_script_with_specified_target) :call_script_with_default_target echo ant default-target ::when no argument present, assumes default target ant pause goto end :call_script_with_specified_target echo ant %target% ant %target% goto end :end pause
when type clean
(at prompt) works expected, when hit enter nothings happen.
the facts:
set /p target=please enter target:
command keeps value oftarget
variable unchanged if user hits enter;%target%
evaluates empty string if not initialised. hence,if %target%=="" (...
evaluates syntactically wrongif =="" (...
, raises error.
either use if "%target%"=="" (...
, or simplify script equivalent
@echo off set "target=" set /p target=please enter target: call ant %target% :end pause
Comments
Post a Comment