3
我正在執行一個下面的程序,它通過java調用shell,我得到excepton請幫助我。Java IOException
程序:
import java.io.*;
import java.util.*;
public class ProcessExample {
/**
* @param args
*/
public static void main(String args[]) throws IOException {
File file=new File("/opt/nilesh/fazal");
ProcessBuilder processBuilder = new ProcessBuilder("./LicenseGen.sh --batchfile commands.txt");
processBuilder.directory(file);
processBuilder.redirectErrorStream(true);
System.out.println("nilesh");
Process process=processBuilder.start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
System.out.printf("Output of running %s is:",
Arrays.toString(args));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
OutputStream os=process.getOutputStream();
OutputStreamWriter osw=new OutputStreamWriter(os);
BufferedWriter bw=new BufferedWriter(osw);
bw.write("create licensekey -x license-input.xml");
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
}
和異常
Excepton:Exception in thread "main" java.io.IOException: Cannot run program "./LicenseGen.sh --batchfile commands.tx": java.io.IOException: error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
at ProcessExample.main(ProcessExample.java:23)
Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
at java.lang.ProcessImpl.start(ProcessImpl.java:65)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
... 1 more
不要寫新的問題。只是在同一個問題上討論你的主題:http://stackoverflow.com/questions/5855768/to-run-shell-script-through-java – 2011-05-03 05:45:09
感謝兄弟的工作 – 2011-05-03 06:05:43