From ad42b7ebf6cc381920e6907febe301fd34b6780a Mon Sep 17 00:00:00 2001 From: Craig Macdonald Date: Thu, 9 Apr 2020 01:39:49 +0100 Subject: [PATCH] handle no java installed case based on exit code --- jnius/jnius_jvm_dlopen.pxi | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/jnius/jnius_jvm_dlopen.pxi b/jnius/jnius_jvm_dlopen.pxi index 1a9cb5b..46b5c6d 100644 --- a/jnius/jnius_jvm_dlopen.pxi +++ b/jnius/jnius_jvm_dlopen.pxi @@ -1,7 +1,7 @@ include "config.pxi" import os from shlex import split -from subprocess import check_output +from subprocess import check_output, CalledProcessError from os.path import dirname, join, exists from os import readlink from sys import platform @@ -58,11 +58,16 @@ cdef find_java_home(): return dirname(dirname(java)).decode('utf8') if platform in ('darwin'): - #its a mac + # its a mac if not exists('/usr/libexec/java_home'): + # I believe this always exists, but just in case + return + try: + java = check_output('/usr/libexec/java_home').strip().decode('utf8') + return java + except CalledProcessError as exc: + # java_home return non-zero exit code if no Javas are installed return - java = check_output('/usr/libexec/java_home').strip().decode('utf8') - return java