Computing.Net > Forums > Programming > Batch file help

Batch file help

Reply to Message Icon

Original Message
Name: dtaiwo
Date: February 24, 2005 at 14:10:34 Pacific
Subject: Batch file help
OS: win 2000
CPU/Ram: P4
Comment:

Hello
I have a batch file that loops through the files in the folder , and runs a program. What i would like is a way to pause between each loop. I would like to wait about 60 sec between each start . Does anyone know how to do that? Or would there be a better way to write the batch file
thx


My batch file is as follows
for %%f in (*.txt) do start C:\PROGRA~1\GAMMAD~1\gm.exe /n /t "F:\Information Technology\Gammadyne\Kathy\Automated\test\%%f"


Report Offensive Message For Removal


Response Number 1
Name: dtech10
Date: February 24, 2005 at 14:50:45 Pacific
Subject: Batch file help
Reply: (edit)

Hi David

You will have to experiment and change the 400000 to a figure the that suits your computer. Your command go's where "echo %%a"
is in the syntax below.

@echo off
for /f %%a in (x.txt) do echo %%a & for /l %%b in (1,1,400000) do echo > nul



Report Offensive Follow Up For Removal

Response Number 2
Name: Mechanix2Go
Date: February 24, 2005 at 23:50:03 Pacific
Subject: Batch file help
Reply: (edit)

dtech10,

Good one.

Another 'el cheapo' timer which is not very system speed dependent:

ping 127.0.0.1 -n xx

where xx is number of seconds.


M2


Report Offensive Follow Up For Removal

Response Number 3
Name: Dr. Nick
Date: February 25, 2005 at 10:52:13 Pacific
Subject: Batch file help
Reply: (edit)

Mechanix2Go has the right idea, but a better option is this:

ping 1.1.1.1 -w ## -n 1

Where ## is the number of seconds * 1000. For 60 seconds, you would use 60000.

This is as accurate as you can get. Since you are pinging a non-existant IP address, it will never respond. The -w tells it how long to wait for a response, so in all it's a very accurate timer (for any batch file purposes anyway).


Report Offensive Follow Up For Removal

Response Number 4
Name: Mechanix2Go
Date: February 25, 2005 at 16:26:53 Pacific
Subject: Batch file help
Reply: (edit)

Hi Dr. Nick,

Good idea.

A little, admittedly unscientific, testing gave these results:

62.6699 seconds 1.1.1.1 -n 60
60.5278 seconds 1.1.1.1 -n 1 -w 60000
59.0448 seconds 127.0.0.1 - n 60

M2


Report Offensive Follow Up For Removal

Response Number 5
Name: Dr. Nick
Date: February 25, 2005 at 17:47:07 Pacific
Subject: Batch file help
Reply: (edit)

Interesting...

Out of curiosity I wrote a quick app in C++ that uses the high-resolution timer and got very similar values to yours.

My reason for using 1.1.1.1 is that if there is no response you can use the -w 60000 option. This is standard and should give very similar results on all systems regardless of system speed. If you ping an IP that is going to respond such as the localhost then the time between each ping may vary based on the speed of the system and with 60 or more pings you could get results varying as much as a several seconds either way.

Haha... after all, batch files need to be EXACTLY on time within 1/1000 of a second :)


Report Offensive Follow Up For Removal


Response Number 6
Name: Dr. Nick
Date: February 25, 2005 at 17:49:22 Pacific
Subject: Batch file help
Reply: (edit)

Oh, except for that first one you did. Pinging 1.1.1.1 with -n 60 actually took something like 300 seconds. Did you mean something else?



Report Offensive Follow Up For Removal

Response Number 7
Name: Mechanix2Go
Date: February 25, 2005 at 21:45:17 Pacific
Subject: Batch file help
Reply: (edit)

Hi Dr. Nick,

With ping 1.1.1.1 -n 60 , I get very nearly 60.

I can't account for the difference.

BTW, my ping defaults to 4 pings, so if I use:

ping 1.1.1.1 -w 60000

I get about 24 sec.

If your ping defaults to 5 pings, that would account for 60 turing into 300.

Would you like to share your C++ timer?

M2


Report Offensive Follow Up For Removal

Response Number 8
Name: Dr. Nick
Date: February 26, 2005 at 16:30:26 Pacific
Subject: Batch file help
Reply: (edit)

Would you like to share your C++ timer?

Sure. I actually worked on it a little bit more since I liked the idea of being able to time things. I added a worker thread so once you start it you can stop it if you want.

It uses the system() call which will add some time to the execution time, but since it's (about) the same amount of time for each call it averages out.

The program

The VC++ project

Don't laugh too hard... it's guarenteed to have bugs :)



Report Offensive Follow Up For Removal

Response Number 9
Name: JackG
Date: February 27, 2005 at 10:16:57 Pacific
Subject: Batch file help
Reply: (edit)

For any version of DOS that has the CHOICE.exe command, including Windows 98/ME (not sure of the NT/XT command prompt) something like the following does not require variable loop delays or other programs and is not OS version dependent.

Where for example the name of the batch file is in the PATH and the current directory is where your *.TXT files are:


@ECHO off
IF x%1==x GOTO LOOP
ECHO Starting %0 for %1 in 60 seconds.
CHOICE /C:N /T:N,60 Wait
CALL C:\What\Ever\Program %1
GOTO EXIT
:LOOP
FOR %%i IN (*.TXT) DO CALL %0 %%i
:EXIT


If you just enter bach file name, it will loop through all matches, pausing 60 seconds before each one. But still allows you to enter N to start it immediatly.

Or to just run one specific instance enter the batch file name followed by the file name (like This_One.TXT), and only the file This_One.TXT will be processed after a 60 second delay.


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch file help

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge