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 need to keep a task running all the time which calls a batch file that is pinging a host to cause a delay before a secondary batch file is called. I have configured it to run each time the system starts however this does not keep the task running. Is there way to achieve this and if so how?

share|improve this question
    
Why not configure it to run every x minutes/hours? Also, can you elaborate on what it is you're trying to do exactly? Maybe there's a better way of achieving the same result. –  Karan Oct 2 '12 at 19:20
1  
You want to look into setting up a system service if you want a process to run all the time and be restarted if it dies. If you just want to run something periodically, used Scheduled Tasks. You might also wish to share some more about your goal (whatever the secondary batch file does), because this sounds a lot like an XY Problem –  Darth Android Oct 2 '12 at 19:20
    
@Karan - The first batch file pings a host e.g. 127.0.0.1 twice with a delay of 6 seconds and once it completes, it calls a secondary batch file that goes through a sequence of events e.g. copy, move, delete, etc. The intention is that each time a person places a file in a directory, the aforementioned sequence of events kick of automatically. –  PeanutsMonkey Oct 2 '12 at 19:24
    
@Darth Android - I did look at setting up a system service however could not find a resource that described how to set up a system service that calls a batch file. First time I ever heard of the use of a XY problem. –  PeanutsMonkey Oct 2 '12 at 19:24
    
@PeanutsMonkey In this case, I would recommend asking your "X" question as a new question here if it's not already answered: "How can I execute a batch file every time a user modifies any file inside of a folder?" Using timed batch files seems kludgy, and you might find a better answer. (Quick search shows that it's been answered for linux and OSX, so a question/answer on how to do it with Windows would be a valuable addition to Super User) –  Darth Android Oct 2 '12 at 19:55
add comment

1 Answer

up vote 3 down vote accepted

srvany can be used to run a batch file as a service. It is a Microsoft-created utility. If you're intent on using a Scheduled Task, you'll just have to set it to run every fifteen seconds or something.

Also, I would recommend using the timeout command for your wait. It's cleaner than using ping. Something like:

:JUMP
timeout /t 6
call "<SECOND_BATCH_FILE>"
goto :JUMP
share|improve this answer
    
Can it be run on Windows 2008 R2? –  PeanutsMonkey Oct 2 '12 at 21:18
    
Yes, it can. timeout is packaged in Server 2008, and srvany runs without issues. I've used it on a Server 2008 machine before and had no problems. –  Kasius Oct 5 '12 at 13:50
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.