1
私はimacとmacの両方でintellijを使用しています。私のMacの本で次のコードを実行すると、すべてが動作します。javaプロセスビルダーが環境へのパスを追加していません
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class Main {
public ProcessBuilder pb;
public Main(){
try {
pb = new ProcessBuilder();
pb.directory(new File("~/IdeaProjects/test"));
Map<String, String> env;
env = pb.environment();
env.put("PATH", "/usr/local/fsl/bin/");
} catch (Exception e) {
e.printStackTrace();
}
}
public void getMeanImage(String base, String file){
List<String> cmd = new LinkedList<>();
cmd.add("fslmaths");
cmd.add(base + file);
cmd.add("-Tmean");
cmd.add(base + file + "_mean");
pb.command(cmd);
try {
String s = "";
Process p = pb.start();
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String [ ] args) {
Main m = new Main();
m.getMeanImage("", "scan.nii.gz");
}
}
私は問題にぶつかります。 printenvで使用されているPATH値をコピーしました。
env.put("PATH", "/usr/local/fsl/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin");
私は例外を取得:
java.io.IOException: Cannot run program "fslmaths" (in directory "~/IdeaProjects/test"): error=2, No such file or directory
はなぜプロセスビルダーは、IMACには/ usr/local/FSL/binにプログラムfslmathsを見つけることができませんか?事前に
which fslmaths
/usr/local/fsl/bin/fslmaths
おかげで、 マーティン
'pb.directory(新しいファイル(〜/ IdeaProjects/test))')は実際にホームディレクトリに新しいサブディレクトリを作成し、 '〜'という名前のディレクトリではありませんか? –