Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Use Python's subprocess library and the third-party psutil library to
- (1) call a .bat file and run as a subprocess,
- (2) continue to do some things in Python,
- (3) close the spawned subprocess, and then end the program.
- """
- import subprocess
- import time
- import psutil
- def pauseTime(num):
- print("\t", num)
- time.sleep(1)
- # Kick off RUNSERVER.bat as a subprocess
- proc = subprocess.Popen("RUNSERVER.bat", creationflags=subprocess.CREATE_NEW_CONSOLE)
- # While subprocess is running in a new console window, print some things out to the original console window.
- [pauseTime(num) for num in list(range(10))]
- # Create a psutil object as pobj, and then kill all of its child processes.
- pobj = psutil.Process(proc.pid)
- for c in pobj.children(recursive=True):
- # list children & kill them
- c.kill()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement