| 1. |
Solve : Batch File With NO LABLES? |
|
Answer» @ECHO OFF May we have an example? Well, I'm sure someone else could cook up a better example but here's one: Batch 1: Code: [Select]@echo off SET /p ANS=Choice? IF "%ANS%"=="Y" ( CALL bat2.cmd ) IF "%ANS%"=="N" ( CALL bat3.cmd ) Batch 2 (bat2.cmd) Code: [Select]echo You called Yes! pause >nul Batch 3 (bat3.cmd) Code: [Select]echo You called No! pause >nul By answering yes or no, you branch out by calling other batch files instead of jumping to labels. Again, I don't know why you would want to take this route as it is tedious and unreasonable.You can eliminate the calls with something LIKE this: Code: [Select]@echo off setlocal set /p ans=choice? if /i "%ans%"=="y" echo You Called Yes if /i "%ans%"=="n" echo You Called No pause > nul Agree with previous POSTER, batch code is already obtuse and obscure so why make things more difficult for yourself? Quote The above code does nothing. Of course not, it was in response to the previous poster as a alternative to using calls. The OP apparently wants to eliminate :labels. The following snippet accomplishes that, but READABILITY plunges near zero. Code: [Select]@echo off setlocal set /p ans=choice? if /i "%ans%"=="y" (echo You Entered Yes && echo Whooppee - isn't this exciting! ) else if /i "%ans%"=="n" (echo You Called No && echo How Negative! ) else (echo Invalid Entry, Try Again && %0) Just curious why OP doesn't want to use all the features available. |
|