-4

このコードの使用中にランタイム例外が発生しています

Runtime rt = Runtime.getRuntime();
System.out.println("Executing " + "uname -a");
Process x = rt.exec("ping IP Address of system");
BufferedReader stdInput =
    new BufferedReader(new InputStreamReader(x.getInputStream()));
BufferedReader stdError =
    new BufferedReader(new InputStreamReader(x.getErrorStream()));
String line = null;
while ((line = stdInput.readLine()) != null) {
    System.out.println(line);
}
x.waitFor();        
4

1 に答える 1

0

この方法で試してみてください..

public class PingClass {

    public void pingIt(){

        InetAddress addr;
        try {
            String line;

            Process p = Runtime.getRuntime().exec(
                    "C:/windows/system32/ping.exe 192.168.2.2");

            /**
             * Create a buffered reader from the Process' input stream.
             */
            BufferedReader input = new BufferedReader(new InputStreamReader(p
                    .getInputStream()));

            /**
             * Loop through the input stream to print the program output into console.
             */
            ArrayList<String> str = new ArrayList<String>();
            while ((line = input.readLine()) != null) {
                str.add(line);
                System.out.println(line);

            }
            /**
             * Finally close the reader
             */
            input.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }   


    public static void main(String[] args){


        new PingClass().pingIt();
    }

}
于 2012-07-03T09:29:43.137 に答える