2013-04-06 48 views
0

我試圖向Aptana添加一個功能,並且此功能要求我查明系統中的寶石位置。在紅寶石我會運行一個命令像...從Aptana/Eclipse中調用shell命令

gem_folder_path = `rvm gemdir` 

在java中顯然還有更多的因素來處理,但似乎我一直在努力的Java解決方案來實現將不會在範圍內工作eclipse/Aptana IDE(我測試過它是獨立的,在我的helloworld.java文件中工作正常)。 shell命令是否被禁用?

這是我目前的Java解決方案,它不起作用。

public static String getGemsDirectory() 
{ 
    try 
    { 
     Process proc = Runtime.getRuntime().exec("which ruby"); 

     BufferedReader stdInput = new BufferedReader(new 
             InputStreamReader(proc.getInputStream())); 

     BufferedReader stdError = new BufferedReader(new 
             InputStreamReader(proc.getErrorStream())); 


     String s; 
     String commandOutput = ""; 
     // read the output from the command 
     System.out.println("Here is the standard output of the command:\n"); 
     while ((s = stdInput.readLine()) != null) { 
      //System.out.println(s); 
      commandOutput += s; 
     } 

     // read any errors from the attempted command 
     System.out.println("Here is the standard error of the command (if any):\n"); 
     while ((String s = stdError.readLine()) != null) { 
      //System.out.println(s); 
      commandOutput += s; 
     } 

     int statusCode = proc.exitValue(); 
     return commandOutput; 
    } 
    catch (IOException e) 
    { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
     return ""; 
    } 
} 

回答