如何通过Java运行Erlang Shell [英] How Can I Run The Erlang Shell Through Java

查看:87
本文介绍了如何通过Java运行Erlang Shell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从java代码运行erlang命令。我已经编码但问题是我无法在终端运行代码。运行erlang的命令即erl没有开始。



代码:

  public   class  erlcmd {

public static < span class =code-keyword> void main( String [] args) throws 例外{

字符串命令[] = { erl 2 + 3。};
for int i = 0; i< command.length; i ++)>
{
进程proc = Runtime.getRuntime()。exec(command [i]);

// 读取输出

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

字符串 line = ;
while ((line = reader.readLine())!= null){
System.out.print(line + \ n);
}
proc.waitFor();
}
}
}

解决方案

您对 exec的调用只发送数组的第一个元素:没有参数的命令名。它应该是:

进程proc = Runtime.getRuntime()。exec(命令); 



as在 http:// docs中描述.oracle.com / javase / 7 / docs / api / java / lang / Runtime.html #exec(java.lang.String []) [ ^ ]。


i want to run the erlang command from java code.i already did the coding but the problem is i am unable to run code in terminal.the command for running erlang i.e "erl" doesnot get started.

code:

public class erlcmd {

    public static void main(String[] args) throws Exception{

        String command[] = {"erl","2 + 3."};
        for(int i=0;i<command.length;i++)>
        {
            Process proc = Runtime.getRuntime().exec(command[i]);
            
            // Read the output
            
            BufferedReader reader =  
            new BufferedReader(new InputStreamReader(proc.getInputStream()));
            
            String line = "";
            while((line = reader.readLine()) != null) {
                System.out.print(line + "\n");
            }
            proc.waitFor();   
        }
    }
}

解决方案

Your call to exec is only sending the first element of the array: the command name without the parameters. It should be:

Process proc = Runtime.getRuntime().exec(command);


as described at http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#exec(java.lang.String[])[^].


这篇关于如何通过Java运行Erlang Shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆