A way for java to call cmd commands

String cmd = "ping www.baidu.com";
        try {
    
    
            Process process = Runtime.getRuntime().exec(cmd);
            InputStream is = process.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String content = br.readLine();
            while (content != null) {
    
    
                System.out.println(content);
                content = br.readLine();
            }
        } catch (IOException e) {
    
    
            e.printStackTrace();
        }

Guess you like

Origin blog.csdn.net/personal_csdn/article/details/108000486