Created
August 4, 2013 09:02
-
-
Save intco/6149781 to your computer and use it in GitHub Desktop.
A taskkill and tasklist wrapper written in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
import StringIO | |
import csv | |
def taskKill(imageName): | |
return runCmd(['taskkill', '/im', imageName]) | |
def taskList(imageName): | |
(exitcode, stdout, stderr) = runCmd(['tasklist', '/nh', '/fo', 'csv', '/fi', "IMAGENAME eq %s" % imageName]) | |
if exitcode != 0: | |
return [] | |
f = StringIO.StringIO(stdout) | |
reader = csv.reader(f, delimiter=',', quoting=csv.QUOTE_ALL) | |
toReturn = [] | |
for row in reader: | |
if len(row) == 5: | |
toReturn.append(row[1]) | |
return toReturn; | |
def runCmd(cmdArgs): | |
process = subprocess.Popen(cmdArgs, stdout=subprocess.PIPE, shell=True) | |
stdout, stderr = process.communicate() | |
exitcode = process.wait() | |
return (exitcode, stdout, stderr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment