zoukankan      html  css  js  c++  java
  • Java 调用系统系统可执行文件

    public class Test {
    
    
        public static Map<String, String> executeCmd(String cmd) {
            Runtime rt = Runtime.getRuntime(); // 运行时系统获取
            Map<String, String> lineMap = new HashMap<String, String>();//存放返回值
            try {
                Process proc = rt.exec(cmd);// 执行命令
                InputStream stderr = proc.getInputStream();//执行结果 得到进程的标准输出信息流
                InputStreamReader isr = new InputStreamReader(stderr);//将字节流转化成字符流
                BufferedReader br = new BufferedReader(isr);//将字符流以缓存的形式一行一行输出
                String line = null;
                while ((line = br.readLine()) != null) {
                    if (!StringUtils.isEmpty(line)) {
                        String[] strLine = line.split(":");
                        if(strLine.length>=2) {
                            lineMap.put(strLine[0].trim(), strLine[1].trim());
                        }
    
                    }
                }
                br.close();
                isr.close();
                stderr.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return lineMap;
        }
    
        public static void main(String []args){
                executeCmd("mstsc");
        }
    }
  • 相关阅读:
    Redis源码阅读笔记(2)——字典(Map)实现原理
    Partition List ——LeetCode
    docker format (golang template)
    markdown 换行
    pecan快速教程
    nvdimm
    k8s device plugin
    linux 文件同步
    复制MIFARE Classic卡
    install docker swarm on centos
  • 原文地址:https://www.cnblogs.com/bytecodebuffer/p/11298570.html
Copyright © 2011-2022 走看看