[英]invoke shell command from within Aptana/ Eclipse
我正在尝试向Aptana添加功能,并且该功能要求我找出系统上宝石的位置。 在红宝石中,我将运行以下命令:
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都对我有效:http://www.java-programming.info/tutorial/pdf/java/22-Native-Apps.pdf
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.