title: Terminate an external program and close all its active windows with python
body: <p>I am working from a windows platform. I have been learning different ways to launch an external process using python. Using my own examples I can:</p>
  
  <pre><code>os.system("C:\mainfolder\menu.exe C:\others\file1.inp C:\others\file2.inp")
  </code></pre>
  
  <p>or</p>
  
  <pre><code>os.popen("C:\mainfolder\menu.exe C:\others\file1.inp C:\others\file2.inp")
  </code></pre>
  
  <p>or  </p>
  
  <pre><code>subprocess.call(["C:\mainfolder\menu.exe","C:\others\file1.inp" "C:\others\file2.inp"])
  </code></pre>
  
  <p>where:</p>
  
  <p>menu.exe: is my external program.</p>
  
  <p>file1 and file2: are input files to my external program.</p>
  
  <p>All the above works perfectly fine, but I cannot find the way to terminate the process, including its active window for any of these cases, without having to click on the close icon from the top right of the launched window. 
  However, if I type taskkill /im menu.exe on the command prompt I manage what I am looking for.</p>
  
  <p>Is there any way to get the same using python?. Just looking for something simple as I do not know too much Python.</p>
  
  <p>I tried with: </p>
  
  <pre><code>    os.system("taskkill /im menu.exe") 
  </code></pre>
  
  <p>but it does not close the window that my external program launches.</p>