Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. """
  2. Use Python's subprocess library and the third-party psutil library to
  3. (1) call a .bat file and run as a subprocess,
  4. (2) continue to do some things in Python,
  5. (3) close the spawned subprocess, and then end the program.
  6. """
  7. import subprocess
  8. import time
  9. import psutil
  10.  
  11. def pauseTime(num):
  12. print("\t", num)
  13. time.sleep(1)
  14.  
  15. # Kick off RUNSERVER.bat as a subprocess
  16. proc = subprocess.Popen("RUNSERVER.bat", creationflags=subprocess.CREATE_NEW_CONSOLE)
  17.  
  18.  
  19. # While subprocess is running in a new console window, print some things out to the original console window.
  20. [pauseTime(num) for num in list(range(10))]
  21.  
  22. # Create a psutil object as pobj, and then kill all of its child processes.
  23. pobj = psutil.Process(proc.pid)
  24.  
  25. for c in pobj.children(recursive=True):
  26. # list children & kill them
  27. c.kill()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement