I want to run a shell script through java. I use the tool to create a license. It can be called using the command. /LicenseGen.sh. I need to run another command to create a license -x license-input.xml which creates a new licensekey.xml file, where license-input.xml is the input file and licensekey is the XML output file, as possible in java, please help me .
my code
import java.io.*;
import java.util.*;
public class ProcessExample {
public static void main(String args[]) throws IOException {
File file=new File("/opt");
ProcessBuilder processBuilder = new ProcessBuilder("./LicenseGen.sh");
processBuilder.directory(file);
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);
}
}
}
source
share