I've checked many threads about running external programs but they cant solve my problem. for running Siesta (DFT Calculation) I have to use something like this (Si.fdf is the input file): siesta < Si.fdf I'm using this code:
public static void main(String argv[]) throws IOException {
Runtime r = Runtime.getRuntime();
Process p;
BufferedReader is;
String line;
System.out.println("siesta < Si.fdf");
p = r.exec("siesta < Si.fdf");
System.out.println("In Main after exec");
is = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = is.readLine()) != null)
System.out.println(line);
System.out.println("In Main after EOF");
System.out.flush();
try {
p.waitFor();
} catch (InterruptedException e) {
System.err.println(e); //
return;
}
System.err.println("Process done, exit status was " + p.exitValue());
return;
}
but this code only runs Siesta without any input file.
答案 0 :(得分:0)
最后我解决了这个问题。我向终端添加一个批处理文件,程序控制它的内容。通过运行此批处理文件,问题得以解决。
public static void writeBatchFile(String batchFileName, String fileName, String inputFile) throws Exception{
FileWriter write = new FileWriter(batchFileName);
PrintWriter print_line = new PrintWriter(write);
print_line.println("#!/bin/bash");
print_line.println("siesta < "+ inputFile +".fdf"+ " > " + fileName + ".out");
print_line.close();
}