title: What's the best way to stop a batch script after a specified amount of time?
body: <p>I'm writing a batch script where I want the user to be able to control how long the script runs. When running it from the command line, the user will pass in a switch like this:</p>
  
  <pre><code>./myscript --stop-after 30
  </code></pre>
  
  <p>which means that the script will keep doing its job, and check every iteration how much time has passed. If more than a half a minute has passed, then it'll quit. How would I implement this in a batch script?</p>
  
  <p>For reference, here is the code I have so far:</p>
  
  <pre><code>:parseArgs
  
  if "%~1" == "" goto doneParsing
  
  if /i "%~1" == "--stop-after" (
      shift
      set "duration=%~1"
  )
  
  :: Parse some other options...
  
  shift
  goto parseArgs
  
  :doneParsing
  
  :: Now do the actual work (psuedocode)
  
  set "start=getCurrentTime"
  set "end=%start% + %duration%"
  
  while getCurrentTime &lt; %end% (
      :: Do some lengthy task...
  )
  </code></pre>
  
  <p>How would I go about implementing the latter part of the script, after parsing the options?</p>
  
  <p>Thanks for helping.</p>