I want to run a shell script through java .I am using license generation tool,It can be call with the help of ./LicenseGen.sh command,under it I require to execute another command
create licensekey -x license-input.xml
which create a new licensekey.xml file where license-input.xml is a input file and licensekey is a output xml file how it is posssible in java please help me.
my code is
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);
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…