编程使用java运行命令shell(SIPp)

时间:2014-05-08 10:44:39

标签: java

如果我运行此代码,我在eclipse控制台上没有找到任何东西,但在终端中,程序SIPp运行正常

public class run {
    public static void main(String[] args) throws IOException {
        ProcessBuilder builder = new ProcessBuilder("sipp","-sn", "uas");
        Map<String, String> environment = builder.environment();
        Process javap = builder.start();
        InputStreamReader tempReader = new InputStreamReader(new  BufferedInputStream(javap.getInputStream()));
        BufferedReader reader = new BufferedReader(tempReader);
        while (true){
            String line = reader.readLine();
            if (line == null)
                break;
            System.out.println(line);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

按照以下

更改您的while循环
String line;
BufferedReader reader = new BufferedReader(tempReader);
    while ((line=reader.readLine()) != null){
       System.out.println(line);
    }

希望这会给你一个想法。