【发布时间】:2011-05-02 09:57:22
【问题描述】:
我想通过java运行一个shell脚本。我正在使用许可证生成工具,它可以在./LicenseGen.sh命令的帮助下调用,在它下面我需要执行另一个命令 创建 licensekey -x license-input.xml 它创建了一个新的 licensekey.xml 文件,其中 license-input.xml 是一个输入文件,而 licensekey 是一个输出 xml 文件,它在 java 中是如何实现的,请帮助我。
我的代码是
import java.io.*;
import java.util.*;
public class ProcessExample {
/**
* @param args
*/
public static void main(String args[]) throws IOException {
File file=new File("/opt");
// List<String> list=new List<String>();
ProcessBuilder processBuilder = new ProcessBuilder("./LicenseGen.sh");
processBuilder.directory(file);
Process process=processBuilder.start();
//processBuilder.command("create licensekey -x license-input.xml");
//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);
}
}
}
【问题讨论】:
-
你不应该为同一问题提出新问题*.com/questions/5831265/java-shell-script-question