Skip to content
This repository was archived by the owner on Dec 29, 2025. It is now read-only.

Commit 08f6742

Browse files
authored
Merge pull request #38 from lilafian/main
Make 'kill' command cross-platform
2 parents 5e20318 + 637cfd5 commit 08f6742

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

poly.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,13 +424,22 @@ def copy(self, source, destination):
424424

425425
def kill(self, process_name):
426426
try:
427-
result = subprocess.run(
428-
["taskkill", "/F", "/IM", process_name],
429-
capture_output=True,
430-
text=True
431-
)
427+
if os.name == "nt":
428+
result = subprocess.run(
429+
["taskkill", "/F", "/IM", process_name],
430+
capture_output=True,
431+
text=True
432+
)
433+
no_output_text = f"No output from kill for '{process_name}'"
434+
else:
435+
result = subprocess.run(
436+
["pkill", "-9", process_name],
437+
capture_output=True,
438+
text=True
439+
)
440+
no_output_text = ""
432441
output = (result.stdout or "") + (result.stderr or "")
433-
self.add(output.strip() or f"No output from taskkill for '{process_name}'")
442+
self.add(output.strip() or no_output_text)
434443
except FileNotFoundError:
435444
self.add("kill: system command not found on system")
436445
except Exception as e:

0 commit comments

Comments
 (0)