Conditional Statements in Batch File -
i have written ms dos batch file runs series of commands.
each command invokes program specific parameters. automate this, combined commands.
the structure of batch file shown below:
@echo off if %1 == "b1" ( command 1 command 2 command 3 .... ) else ( command command b command c )
i invoke shown below:
test.bat b1
if pass b1 argument batch file, process series of commands, command 1, command 2, command 3 , on.
similarly, if want execute series of commands mentioned in else section, pass argument:
test.bat abc
since argument passed batch file not equal b1, start executing else section of batch file. here argument passing (in case, abc) required commands, command a, command b, command c , on parameter.
all works pretty good.
however, issue facing is, if want terminate batch file in between (by pressing ctrl + c), not prompt me option: want terminate batch operation? y/n
for instance, let say, batch file processing series of commands in else section. currently, assume executing command a. if press ctrl + c, instead of prompting me cancel operation cancels execution of command , automatically proceeds command b. if press ctrl + c again, cancels command b , proceeds command c , on.
now, on other hand, if write batch file shown below:
@echo off command command b command c
and invoke command line as:
test.bat abc
now, when press ctrl + c while batch file being executed, prompts me cancel batch operation expected.
it appears when add conditional statement in batch file, functionality of ctrl + c modified in way.
how can fix issue?
thanks.
i tried , seemed work expected:
@echo off if "x%1x" == "xb1x" ( echo yes dir ... ) else ( echo no not dir ... )
(where ...
repeats previous pair of lines 100 times give time press ctrl-c). did prompt, though break occurred inside if
... else
.
so suspect there's unusual commands you're running, , if
behaviour red herring. in particular, launching programs, expect ctrl-c gets passed directly program being run instead of batch file launched it.
Comments
Post a Comment