Java 从Aptana/Eclipse中调用shell命令
我正在尝试向Aptana添加一个功能,这个功能要求我找出系统中的gems在哪里。在ruby中,我会运行如下命令Java 从Aptana/Eclipse中调用shell命令,java,eclipse,aptana,Java,Eclipse,Aptana,我正在尝试向Aptana添加一个功能,这个功能要求我找出系统中的gems在哪里。在ruby中,我会运行如下命令 gem_folder_path = `rvm gemdir` 在java中,显然有更多的因素需要处理,但我尝试实现的java解决方案似乎无法在eclipse/Aptana IDE的范围内工作(我已经单独测试了它,并且在我的helloworld.java文件中工作良好)。shell命令被禁用了吗 这是我目前的java解决方案,它不起作用 public static String get
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 "";
}
}
本教程将向您展示如何运行本机OS命令。在Eclipse/Tomcat和Java中为我工作
谢谢你的图坦卡蒙,但图坦卡蒙包含了我在谷歌上找到的解决方案。这个问题似乎是针对大型java应用程序或eclipse插件的。