Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ueffel committed Dec 7, 2018
1 parent 9d5f057 commit 373138f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions kill.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ def _get_windows(self):
handles = AltTab.list_alttab_windows()
except OSError:
self.err("Failed to list windows.", traceback.format_exc())
return

self._processes_with_window = {}

Expand Down Expand Up @@ -309,6 +310,7 @@ def _get_processes_from_ext_call(self):
self.err(err)

# Parsing process list from output
outstr = None
for enc in ["cp437", "cp850", "cp1252", "utf8"]:
try:
output = output.replace(b"\r\r", b"\r")
Expand All @@ -317,6 +319,10 @@ def _get_processes_from_ext_call(self):
except UnicodeDecodeError:
self.dbg(enc, "threw exception")

if not outstr:
self.warn("decoding of output failed")
return

info = {}
for line in outstr.splitlines():
if line.strip() == "":
Expand Down Expand Up @@ -416,6 +422,7 @@ def _is_running_from_ext_call(self, pid):
self.err(err)

# Parsing process list from output
outstr = None
for enc in ["cp437", "cp850", "cp1252", "utf8"]:
try:
output = output.replace(b"\r\r", b"\r")
Expand All @@ -424,6 +431,10 @@ def _is_running_from_ext_call(self, pid):
except UnicodeDecodeError:
self.dbg(enc, "threw exception")

if not outstr:
self.warn("decoding of output failed")
return False

running = "ProcessId={}".format(pid) in outstr.splitlines()
self.dbg("(wmic) process with id ", pid, "running" if running else "not running")
return running
Expand Down

0 comments on commit 373138f

Please sign in to comment.