JAVA 调用C 语言程序,并且进行传参收结果等操作

import java.io.*;
import java.lang.*;
class test3{
       public static void main(String []args) throws IOException{
                long a = System.currentTimeMillis();
                Process process = Runtime.getRuntime().exec("/home/zhangdi/traceroute_l");//这是外部程序所在目录,切记返回类型为process
                PrintStream outputWriter = new PrintStream(new BufferedOutputStream(process.getOutputStream()));
                outputWriter.println("218.198.33.204");
                outputWriter.flush();//这里一定要刷新缓冲区,不然参数传不过去
                outputWriter.println("-T");
                outputWriter.flush();
                outputWriter.println("-80");
                outputWriter.flush();
                outputWriter.println("4");
                outputWriter.flush();
                outputWriter.println("192.168.1.30");
                outputWriter.flush();
                BufferedReader addResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
                String line;
                while((line=addResult.readLine())!=null)
                {
                     
                        System.out.println(line);
                 }
                long b = System.currentTimeMillis();
                System.out.println(b-a);
}


}

你可能感兴趣的:(python)