• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

What is the DOS command to repeat the last command?

Zenmervolt

Elite member
I'm trying to write a batch file that will run a command a few times in repetition, is there a repeat command that I can use instead of just putting the same command in the batch file over and over again?

Zenmervolt
 
Can't you do if...then statements in batch files?

Been a while since I've had to write one, maybe you can't...

Viper GTS
 
Couple ways (without copying the sequence repeatedly):

Batch files can use Labels. If you put a "Start:" (no quotes, see the colon) at the top, for example, you can then say "goto start" at the end and it'll loop till you kill it.

******

If you want to do iterative subsitution (loop with different values each time):

For %%1 in (Val1 Val2 Val3...etc) DO

...the stuff you want to do goes here, the %%variables are replaced with the current value from the sub list at the top

Loop

*********

and to do a conditional ...

if %%1 = "Whatevervaluegoeshere" then goto (your label to the exit routine here, no parens)

I may be off on some of the finer details (like whether you'd have to say goto Start or start🙂, but if you play in this neighborhood, you should be able to get it together.

Good Luck

Scott
 
AH! Thank you, I was forgetting the colon ":". And yes, you can do an if...then statement in a batch file, at least Win2K's help file says you can.

Zenmervolt

EDIT: <<"del autoexec.bat">> hahaha. However, Win 2K really wouldn't mind that, since there is no autoexec.bat. I've played around with the autoexec.bat and config.sys files on DOS systems enough to know not to do that. (Even though there are some people to whose systems that might be a very thereputic thing to do....)
 
umm well you can hit F8 I think at the prompt to call up last command, or if you have doskeys loaded you can hit the up arrow. but neither of those do you any good in a batch file.


but you can just use copy + paste and its real easy to repeat the same command over and over. or a loop as specified above
 
From the keyboard, "F3" repeats the last command. "F1" retypes it one letter at a time.

DOSKEY-like functions are enabled by default in WIN2K, and I'm pretty sure XP as well.

-Scott
 
F3 at the prompt to call up the last command.

Doesn't apply to a batch file though.

I have written very short programs in basic and then called then from a batch file to handle some things.

Before anyone flames me for using basic, that was almost 20 years ago. BasicA was cutting edge then.
 
Back
Top