2013-10-25 22 views
2

我想通过我的Java应用程序搜索特定进程,以便我可以验证我的应用程序是否正在运行(Apache)。这是对班级的简化。Java运行时获取Garbage选项错误

package com.tecsys.sm.test; 

import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 

import com.tecsys.sm.util.FinalValues; 

public class ShellRuntimeCommands { 
    public static void showApacheProcess(){ 
     try { 
      String command = "ps ax | grep \"/apps/apache/2.4.4/bin/httpd\" | grep -v \"grep\""; 
      System.out.println("La commande est: " + command); 
      final Process proc = Runtime.getRuntime().exec(command); 
      BufferedReader br = new BufferedReader(new InputStreamReader(proc.getErrorStream())); 
      String line = br.readLine(); 
      System.out.println("The Error line is "+line); 
      String status; 
      if(line!=null && line!=""){ 
       status = FinalValues.STARTED_STATUS; 
      }else{ 
       status = FinalValues.STOPPED_STATUS; 
      } 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 
    public static void main(String[] args){ 
    ShellRuntimeCommands.showApacheProcess(); 
    } 
} 

下面是输出:

La commande est: ps ax | grep "/apps/apache/2.4.4/bin/httpd" | grep -v "grep" 
The line is ERROR: Garbage option. 

的事情是,我复制粘贴输出字符串命令我在终端执行,它工作正常,但它不是通过java运行工作。

回答