Computing.Net > Forums > Disk Operating System > how do I do a loop in a DOS batch file?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

how do I do a loop in a DOS batch file?

Reply to Message Icon

Name: Kelly
Date: May 10, 2001 at 10:59:00 Pacific
Comment:

I want to run this java program of mine every wednesday and saturday, so I was told a batch file was the best way. Can someone guide me as to how I can tell if it's wed or saturday, and also how to do an infinite loop so my batch file runs all the time?



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: May 10, 2001 at 15:09:52 Pacific
Reply:

Hi.
You want a loop so the batch checks if its wed/sat all the time, is that it?
If that's it, here goes it. I don't think it would be a good idea to put a "call sample.bat" at your autoexec.bat file. You'd better put it to run at the programs menu "startup"

------------------------------
::sample.bat
@echo off
:loop
echo. |DATE |FIND "Current" > out.bat
echo SET DAY=%%3> current.bat
call out.bat
IF "%DAY%"=="Wed" goto run
IF "%DAY%"=="Sat" goto run
goto loop

:run
program.exe
------------------------------

Well, that's it. That may consume some memory because of the fact it runs and runs with no break. I think you should use this second sample, that checks for the day every ten minutes:

-----------------------------
::sample2.bat
@echo off
:loop
SET TIME=
echo. |DATE |FIND "Current" > out.bat
echo SET DAY=%%3> current.bat
call out.bat
IF "%DAY%"=="Wed" goto run
IF "%DAY%"=="Sat" goto run
:timeloop
choice /n /c:yn /t:y,60 > nul
if "%time%"=="9" goto loop
if "%time%"=="8" set time=9
if "%time%"=="7" set time=8
if "%time%"=="6" set time=7
if "%time%"=="5" set time=6
if "%time%"=="4" set time=5
if "%time%"=="3" set time=4
if "%time%"=="2" set time=3
if "%time%"=="1" set time=2
if "%time%"=="" set time=1
goto timeloop

:run
call program.exe
-------------------------------

That's it. I hope it was helpful

-- SECRET_DOOM --

email: secret_doom@hotmail.com


0

Response Number 2
Name: Secret_Doom
Date: May 10, 2001 at 15:11:56 Pacific
Reply:

Hu.. I was wondering... Why don't you use windows schedule program?


0

Response Number 3
Name: DoOMsdAY
Date: May 10, 2001 at 16:47:50 Pacific
Reply:

Yeppers, my sentiments exactly. You can us 'at' in NT or Windows Scheduler or whatever it is in 9x.


0

Response Number 4
Name: Kelly
Date: May 11, 2001 at 07:03:58 Pacific
Reply:

That's exactly what I want to do, except for I need to check if it's after 20:00 hrs (eight o'clock in the evening) both days before I can run the java program I want to run. Can you show me how to include this into one of the above batch files? I'd really appreciate it.

Also, what's the windows schedule program and how do I run it under Windows NT?


0

Response Number 5
Name: Secret_Doom
Date: May 11, 2001 at 10:49:51 Pacific
Reply:

Hi again.
Well, checking if it's after 20:00h is REALLY more complicated. I could do it if ya really need it, but I think a win schedule program would be better for that.

Try searching at:
STARTMENU - PROGRAMS - ACESSORIES - SYSTEM TOOLS

Or something like that. If ya can't find, search for it at windows install:

CONTROL PANEL - Add/Remove Programs - Windows install

Well, that's all. If ya still need the batch file, letme know

-- SECRET_DOOM --

email: secret_doom@hotmail.com


0

Related Posts

See More



Response Number 6
Name: World Library
Date: May 11, 2001 at 14:31:31 Pacific
Reply:

W.L. sees an interesting bat upped by Secret Doom.

What a fine and usefull "Paper doll"!

It is copied and pasted and sent into the Library for future generations.........................................

And the world continues to turn.

W.L.


0

Response Number 7
Name: Secret_Doom
Date: May 11, 2001 at 15:46:00 Pacific
Reply:

I'm glad ;D


0

Response Number 8
Name: DoOMsdAY
Date: May 11, 2001 at 15:59:59 Pacific
Reply:

NT has a command called 'at' - At Time. Open a "DOS" box and type 'at /?' or enter the Windows Help and look up 'at'. It's a bit complicated-looking at first but I can try and help you through it if you like - although it's been a while since I've used it myself.


0

Response Number 9
Name: kelly
Date: May 13, 2001 at 08:31:06 Pacific
Reply:

Thanks for all that help,

I'm going to look into the windows scheduler thing and the At thing, and then I'll let you know if I need the batch file or not, or if I need help with the at...

Thanks for all of your help,

Kelly.


0

Response Number 10
Name: kelly
Date: May 13, 2001 at 08:37:41 Pacific
Reply:

hey DoOMsdAY,

I've just looked at the 'at' command, and it seems pretty ok. A couple of questions though, like:
1. where do I get the id from
2. Do I just type in 'at .............' at the command line once, and then my program will be scheduled?

Thanks,
Kelly.


0

Response Number 11
Name: kelly
Date: May 13, 2001 at 08:49:13 Pacific
Reply:

hey Secret_doom,

I found WinAT under my start menu, and it does exactly what I want to do!
But what do I write under 'command' - the name of the file to run (including the path)?

Thanks,

Kelly.


0

Response Number 12
Name: DoOMsdAY
Date: May 13, 2001 at 10:57:14 Pacific
Reply:

[1] id is not needed.
[2] If you do the /every: version, it will automatically run each Tuesday for example. So yes, you only have to type it in once per scheduled process.


0

Response Number 13
Name: Secret_Doom
Date: May 13, 2001 at 11:02:11 Pacific
Reply:

Yeah, I think you should put the program's name with fullpath (just like you said)

-- SECRET_DOOM --


0

Response Number 14
Name: kelly
Date: May 14, 2001 at 03:43:08 Pacific
Reply:

Thanks to both of you for your help,

I'll try it and keep you posted if I'm successful!

Thanks again,

Kelly.


0

Response Number 15
Name: DoOMsdAY
Date: May 14, 2001 at 04:12:56 Pacific
Reply:

Yeppers. :)


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: how do I do a loop in a DOS batch file?

How can I rename all files in a directory ? www.computing.net/answers/dos/how-can-i-rename-all-files-in-a-directory-/2201.html

Help me! How can I do a unic partit www.computing.net/answers/dos/help-me-how-can-i-do-a-unic-partit/11568.html

How can I close a program in dos? www.computing.net/answers/dos/how-can-i-close-a-program-in-dos/13404.html