title: Jenkins - Batch wait till process is up and kill if it hangs
body: <p>I’m using Jenkins on Windows and want to run csscript that launch an application and execute automatic tests, now I want to create a time out so in case the application is running more than about 30 minutes it will be killed,</p>
  
  <p>I have this batch script: first I create a FOR loop that wait till the application is up and then another FOR loop that check if the application is up more than 25 minutes.</p>
  
  <p>The problem is I’m getting this error in the first loop
  Process leaked file descriptors. See <a href="http://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build" rel="nofollow">http://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build</a> for more information
  I read the info on wiki but didn’t really understand how to solve my issue
  Please help</p>
  
  <pre><code>start cscript //nologo D:\tets.vbs
  FOR /L %%A IN (1,1,20) DO (
      echo Round number %%A
  
      REM find the running executable
      tasklist | find /I /C "App.exe" &gt; nul
      echo ERRORLEVEL is !ERRORLEVEL!
      IF !ERRORLEVEL! EQU 0 EXIT
  
      rem wait 3 seconds
      ping 1.1.1.1 -n 1 -w 3000 &gt; nul
  )
  FOR /L %%U IN (1,1,50) DO (
      echo Round number %%U
  
      REM find the running executable
      tasklist | find /I /C "App.exe" &gt; nul
      echo ERRORLEVEL is !ERRORLEVEL!
      if !ERRORLEVEL! EQU 1 EXIT
  
      rem wait 30 seconds
      ping 1.1.1.1 -n 1 -w 30000 &gt; nul
  )
  echo TASKILL
  taskkill /f /im App.exe
  </code></pre>