| 1. |
Solve : Batch program seems to be looping endlessly? |
|
Answer» Created a batchfile that seems to be entering an endless loop and am not sure why. Have you ever done batch files before? Told you I was bad at this. As far as Code: [Select]if %ERRORLEVEL% == 3 GOTO EXITin the first batch file if i select 3 and press enter the batch file will begin executing at :EXIT What follows is merely conformation to exit the batch file.In other languages the IF state rests fir a deterministic truth has has one meaning. In BATCH, the error level is more like a maybe test. I is like asking "How bad was the error?" The answer might not be a direct specific answer. Instead, it rates the error on a scale of bad to worse. Here I am not going to use exact syntax. The is not the point. Q. "Hey batch, how bad was the error. As much as a one? A. if error-level = 1 "Yeah, I can say that it would be. Q. "Hey batch, how bad news in error. As much as a two? A. if error-level = 2 "Yeah, I can say at least a 2.". Q. "Hey batch, how high was the error. MAYE a three?" A. if error-level = 3 "I will say thee, if not more." Q. "Hey batch, did you get error. Up to four?" A. if error-level = 4 "Four for sure, less I don't see." Get it? READ over the examples is samples in the tutorials. BATCH is not like any other task control tool. In your :DRIVEE label you change the current directory, but you do not change it back before you return to MAIN, so I'd wager it cannot find cmdmenusel anymore so you get stuck in an infinite loop. I think that may be the case for your second batch file as well. I'd suggest that you use PUSHD to change to the sysinternals directory, and then before you return you use POPD. I don't think Geek-9pm's COMMENTS are relevant, as he is thinking of a slightly different construct ("IF ERRORLEVEL X ") which is not what you are using. I stand corrected. No excuse. Quote from: BC_Programmer on February 10, 2020, 06:46:33 PM In your :DRIVEE label you change the current directory, but you do not change it back before you return to MAIN, so I'd wager it cannot find cmdmenusel anymore so you get stuck in an infinite loop.Thanks, BC_Programmer, for the tip. It worked perfectly. I deleted the CD line and added the path to the call statement. Can also work if I place the needed batch files in the same directory. |
|