从java代码运行elasticsearch

时间:2015-03-31 16:25:03

标签: windows java-ee elasticsearch cmd

我想从servlet运行弹性搜索。    我在我的servlet中使用此方法来运行elasticsearch,但它似乎不起作用。

ejbsessionbean.runcommand( "cmd C:\\ELK\\elasticsearch\\bin\\elasticsearch";)

runco​​mmand的代码如下:

  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);
   }

}

0 个答案:

没有答案