Skip to content

Commit

Permalink
correct the errors when there are spces in th epath
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Sep 8, 2023
1 parent 4db9ba0 commit 8afd66f
Showing 1 changed file with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -587,7 +588,23 @@ private void retrieveInterprocessingTensors(List<Tensor<?>> 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
Expand All @@ -599,18 +616,19 @@ private List<String> 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<String> command = new LinkedList<String>();
command.add(javaBin);
command.add(padSpecialJavaBin(javaBin));
command.add("-cp");
command.add(classpath);
command.add(className);
Expand Down

0 comments on commit 8afd66f

Please sign in to comment.