title: Can I close the CMD window that opened with subprocess.Popen in Python?
body: <p>I have a program that need to run small tasks in new CMDs.
  For example:</p>
  
  <pre><code>def main()
      some code
      ...
      proc = subprocess.Popen("start.bat")
      some code...
      proc.kill()
  </code></pre>
  
  <p>subprocess,Popen opens a new cmd window and runs "start.bat" in it.
  proc.kill() kills the process but doesn't close the cmd window.
  Is there a way to close this cmd window?</p>
  
  <p>I thought about naming the opened cmd window so i can kill it with the command:</p>
  
  <pre><code>/taskkill /f /im cmdName.exe
  </code></pre>
  
  <p>Is it possible ?if no, What do you suggest ?</p>
  
  <p>Edit, Added Minimal, Complete, and Verifiable example:</p>
  
  <p>a.py:</p>
  
  <pre><code>import subprocess,time
  proc = subprocess.Popen("c.bat",creationflags=subprocess.CREATE_NEW_CONSOLE)
  time.sleep(5)
  proc.kill()
  </code></pre>
  
  <p>b.py</p>
  
  <pre><code>while True:
      print("IN")
  </code></pre>
  
  <p>c.bat</p>
  
  <pre><code>python b.py
  </code></pre>