码迷,mamicode.com
首页 > 编程语言 > 详细

Java程序执行cmd命令

时间:2019-10-30 22:27:28      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:ext   RoCE   edr   simple   exception   cal   while   ade   效果   

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class testjava {
    public static void main(String[] arg) {
        // Java调用 dos命令
        String cmd = "node -v";
        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();
        }


    }
}

效果:

技术图片

Java程序执行cmd命令

标签:ext   RoCE   edr   simple   exception   cal   while   ade   效果   

原文地址:https://www.cnblogs.com/loaderman/p/11768235.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!