title: Inside a batch file, how can I tell whether a process is running?
body: <p>I'd like to write a batch file that checks to see if a process is running, and takes one action if it is, and another action if it isn't.</p>
  
  <p>I know I can use tasklist to list all running processes, but is there a simpler way to directly check on a specific process?</p>
  
  <p>It seems like this should work, but it doesn't:</p>
  
  <pre><code>tasklist /fi "imagename eq firefox.exe" /hn | MyTask
  IF %MyTask%=="" GOTO DO_NOTHING
  'do something here
  :DO_NOTHING
  </code></pre>
  
  <p><strong>Using the solution provided by atzz, here is a complete working demo:</strong></p>
  
  <p><strong>Edit: Simplified, and modified to work under both WinXP and Vista</strong></p>
  
  <pre><code>echo off
  
  set process_1="firefox.exe"
  set process_2="iexplore.exe"
  set ignore_result=INFO:
  
  for /f "usebackq" %%A in (`tasklist /nh /fi "imagename eq %process_1%"`) do if not %%A==%ignore_result% Exit
  for /f "usebackq" %%B in (`tasklist /nh /fi "imagename eq %process_2%"`) do if not %%B==%ignore_result% Exit
  
  start "C:\Program Files\Internet Explorer\iexplore.exe" www.google.com
  </code></pre>