30 lines
704 B
Python
30 lines
704 B
Python
import os
|
|
import platform
|
|
import subprocess
|
|
from typing import Union
|
|
|
|
|
|
def check_exec(name: Union[os.PathLike[str], str]) -> bool:
|
|
if is_windows():
|
|
check_process = subprocess.Popen([
|
|
"where.exe", name
|
|
], stdout=subprocess.PIPE)
|
|
check_process.wait()
|
|
return len(check_process.stdout.readlines()) > 0
|
|
elif is_linux():
|
|
check_process = subprocess.Popen([
|
|
"which", name
|
|
])
|
|
check_process.wait()
|
|
return check_process.returncode == 0
|
|
else:
|
|
return False
|
|
|
|
|
|
def is_windows() -> bool:
|
|
return platform.system().lower() == "windows"
|
|
|
|
|
|
def is_linux() -> bool:
|
|
return platform.system().lower() == "linux"
|