diff --git a/src/main/java/io/bioimage/modelrunner/tensorflow/v1/Tensorflow1Interface.java b/src/main/java/io/bioimage/modelrunner/tensorflow/v1/Tensorflow1Interface.java index db92edd..2eb76e4 100644 --- a/src/main/java/io/bioimage/modelrunner/tensorflow/v1/Tensorflow1Interface.java +++ b/src/main/java/io/bioimage/modelrunner/tensorflow/v1/Tensorflow1Interface.java @@ -46,6 +46,7 @@ import java.nio.ByteBuffer; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.security.CodeSource; @@ -587,7 +588,23 @@ private void retrieveInterprocessingTensors(List> tensors) throws RunM } /** - * Create the arguments needed to execute tensorflow1 in another + * if java bin dir contains any special char, surround it by double quotes + * @param javaBin + * java bin dir + * @return impored java bin dir if needed + */ + private static String padSpecialJavaBin(String javaBin) { + String[] specialChars = new String[] {" "}; + for (String schar : specialChars) { + if (javaBin.contains(schar)) { + return "\"" + javaBin + "\""; + } + } + return javaBin; + } + + /** + * Create the arguments needed to execute tensorflow 2 in another * process with the corresponding tensors * @return the command used to call the separate process * @throws IOException if the command needed to execute interprocessing is too long @@ -599,18 +616,19 @@ private List getProcessCommandsWithoutArgs() throws IOException, URISynt String modelrunnerPath = getPathFromClass(DeepLearningEngineInterface.class); String imglib2Path = getPathFromClass(NativeType.class); - if (modelrunnerPath.endsWith("DeepLearningEngineInterface.class") - && !modelrunnerPath.contains(File.pathSeparator)) + if (modelrunnerPath == null || (modelrunnerPath.endsWith("DeepLearningEngineInterface.class") + && !modelrunnerPath.contains(File.pathSeparator))) modelrunnerPath = System.getProperty("java.class.path"); String classpath = modelrunnerPath + File.pathSeparator + imglib2Path + File.pathSeparator; ProtectionDomain protectionDomain = Tensorflow1Interface.class.getProtectionDomain(); - CodeSource codeSource = protectionDomain.getCodeSource(); - for (File ff : new File(codeSource.getLocation().getPath()).getParentFile().listFiles()) { - classpath += ff.getAbsolutePath() + File.pathSeparator; - } + String codeSource = protectionDomain.getCodeSource().getLocation().getPath(); + String f_name = URLDecoder.decode(codeSource, StandardCharsets.UTF_8.toString()); + for (File ff : new File(f_name).getParentFile().listFiles()) { + classpath += ff.getAbsolutePath() + File.pathSeparator; + } String className = Tensorflow1Interface.class.getName(); List command = new LinkedList(); - command.add(javaBin); + command.add(padSpecialJavaBin(javaBin)); command.add("-cp"); command.add(classpath); command.add(className);