I want to run elastic search from a servlet. I use this method in my servlet to run elasticsearch but it does not seem to work.
ejbsessionbean.runcommand( "cmd C:\\ELK\\elasticsearch\\bin\\elasticsearch";)
The code for runcommand follows:
public static void runcommand(String ch) throws IOException {
if (ch.length() <= 0) {
System.err.println("Need command to run");
System.exit(-1);
}
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(ch);
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
System.out.printf("Output of running %s is:",
ch);
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
Aucun commentaire:
Enregistrer un commentaire