我想从servlet运行弹性搜索。 我在我的servlet中使用此方法来运行elasticsearch,但它似乎不起作用。
ejbsessionbean.runcommand( "cmd C:\\ELK\\elasticsearch\\bin\\elasticsearch";)
runcommand的代码如下:
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);
}
}