Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a batch file:

arp -s 192.168.1.254 xx-xx-xx-xx-xx-xx
ipconfig /flushdns

How can I do these two commands on Windows XP, every 10 seconds?

share|improve this question

migrated from stackoverflow.com Nov 7 '09 at 1:06

This question came from our site for professional and enthusiast programmers.

3  
You can use Windows Scheduled Tasks to get it down to once a minute. –  Jay Riggs Nov 7 '09 at 0:18
    
it is possible with Windows batch: see my solution below. the only problem is cpu usage... –  kokbira Apr 25 '11 at 20:05

8 Answers 8

Try this one:

:loop
arp -s 192.168.1.254 xx-xx-xx-xx-xx-xx
ipconfig /flushdns
ping localhost -n 11 > nul
goto loop

The ping command will execute for 10 seconds, and all the output will be redirected to the NUL device, meaning that you will see no output from the ping command. It works indeed as a "sleep" command would.

share|improve this answer
    
I exclaimed PING! when I saw the question ;) –  Mehmet Ergut Nov 7 '09 at 0:34
1  
Somehow I knew you would! –  Bruno Reis Nov 7 '09 at 0:36
    
Eep. Sorry. I somehow thought they'd have something to do with the ping for waiting. –  Joey Apr 27 '11 at 20:38
:top
arp -s 192.168.1.254 xx-xx-xx-xx-xx-xx
ipconfig /flushdns
sleep 10
goto top

Edit: As mentioned in the comments, SLEEP won't be available in a normal install. You'll need something like the Windows 2003 Resource Kit, or some other trick to simulate it (the ping trick Bruno mentions), and notes to do so can be found here.

share|improve this answer
5  
sleep isn't included by default. You need the resource kit or something to get this? –  marcc Nov 7 '09 at 0:19
    
What exactly do I need? –  steven Nov 7 '09 at 0:21
    
It isn't? I could've sworn it was something I could count on, but I guess like choice it might not be included by standard. I'll look into it more. –  Doug Kavendek Nov 7 '09 at 0:21
    
What is the link to this resource kit? –  steven Nov 7 '09 at 0:23
1  
There's no need to install anything else on windows to "fake" a sleep command. Take a look at my answer for an example. –  Bruno Reis Nov 7 '09 at 0:29

More precise solution ping unexistent host once and set timeout

ping 1.0.0.0 -n 1 -w 10000 >nul

But it generate parasite traffic

share|improve this answer

You could set up a Windows service to run your batch file.

share|improve this answer
1  
How? Example please? –  steven Nov 7 '09 at 0:18
    
Why does everybody want to write a custom service just to do things that the task scheduler is perfectly capable of? –  Joey Apr 27 '11 at 16:06
    
Well, if you have the solution, post that as an answer :). How can we do that in your way? –  kokbira Apr 27 '11 at 17:33

Cheat:

Use this command to pause the batch for 10 seconds

choice /n/t:c,<10>/c:cc

Now, place it in a never ending loop in the batch and voilà!

share|improve this answer
1  
Or, if you want, download the resource kit or write a simple prog to sleep 10. My method however, will mean you can move it to another machine without having to download more software again. –  Dan McG Nov 7 '09 at 0:22
    
I didn't think choice came with XP and later, or at least I haven't seen it on any recent installs. –  Doug Kavendek Nov 7 '09 at 0:29
1  
I'm running vanilla Vista Home Premium on this laptop and it works fine. –  Dan McG Nov 7 '09 at 0:35
    
there is no "choice" for windows xp!!! –  kokbira Apr 25 '11 at 19:27

Install Cygwin which will make sleep and cron available to you (among other things).

share|improve this answer
2  
Overkill for what he is asking! –  Bruno Reis Nov 7 '09 at 0:31

this makes a 10 sec. delay:

timeout /t 10

so try this:

 :loop
 arp -s 192.168.1.254 xx-xx-xx-xx-xx-xx
 ipconfig /flushdns
 timeout /t 10
 goto loop
share|improve this answer

below, it is both an ugly and a beautiful way, an Windows batch file - it consumes a lot of cpu time to do nothing, but it does what you want and is so nice.

SETLOCAL EnableDelayedExpansion

::in seconds
set time2stop=10

:loop1
arp -s 192.168.1.254 xx-xx-xx-xx-xx-xx
ipconfig /flushdns

for /f "tokens=1,2* delims=:" %%i in ("!time!") do (
  set hour1=%%i
  set min1=%%j
  set sec1=%%k
)

for /f "tokens=1* delims=," %%i in ("!sec1!") do (
  set isec1=%%i
)

:loop2

for /f "tokens=1,2* delims=:" %%i in ("!time!") do (
  set hour2=%%i
  set min2=%%j
  set sec2=%%k
)

for /f "tokens=1* delims=," %%i in ("!sec2!") do (
  set isec2=%%i
)

set /a delta=3600*(!hour2!-!hour1!)+60*(!min2!-!min1!)+(!isec2!-!isec1!)
if !delta! geq !time2stop! goto end2

goto loop2

:end2

@echo on

goto loop1
share|improve this answer
    
another way is to do some loop sequence, for example repeating ( for /l %%i in (1,1,65535) do set nothing=0 ) some times and "calibrating" "how many times" you have to repeat testing to result in 10 seconds, hahaha. but it is the ugliest way. –  kokbira Apr 25 '11 at 20:10
    
you can also create some Windows batch to use as functions (one to split time, one to do the waiting...) but it will be more complex... –  kokbira Apr 25 '11 at 20:13
    
I think it will cause a bug if you are using it from 23:59:51 to 23:59:59 - in that case, the batch will wait forever... some "if's" would solve the problem... –  kokbira Apr 25 '11 at 20:17
    
if you want to test for a fixed time (not a time+10sec) you can simply do "if %time% geq 10:30 do goto end". the solution became complex because the sum... –  kokbira Apr 25 '11 at 20:21
    
It's actually horrible. First of all, busy waiting. wasting CPU cycles unnecessarily is never a good idea (unless on embedded hardware). This also doesn't appear to work correctly around midnight. –  Joey Apr 27 '11 at 16:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.