首页 > 编程语言 > 详细

java 执行 exe 文件

时间:2020-09-25 19:02:46      阅读:40      评论:0      收藏:0      [点我收藏+]
package com.example.hostinfo.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class CalabashUtil {
    public static Logger logger = LoggerFactory.getLogger(CalabashUtil.class);

    public static String path = "tools\\Client\\Debug\\";

    private static String program = "Calabash.Plugin.ConsoleApp.exe";

    private static String server = "tools\\Server\\Calabash.Business.Daemon.Host.exe";

    public static boolean getInfo(String platform, String roomNum) throws IOException {
        try {
            String programName = program.substring(program.lastIndexOf("/") + 1, program.lastIndexOf("."));
            List<String> list = new ArrayList<String>();
            list.add("cmd.exe");
            list.add("/c");
            list.add("start");
            list.add("\"" + programName + "\"");
            list.add(program);

            //参数 platform
            list.add(platform);

            //参数 roomNum
            list.add(roomNum);

            ProcessBuilder pBuilder = new ProcessBuilder(list);

            //类似 cd path
            pBuilder.directory(new File(path));
            pBuilder.start();
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        server();
        Thread.sleep(1000*5);
        getInfo("Douyu", "5720533");
//        getInfo("Douyu", "1011");
//        server();
    }

    public static boolean server() throws IOException {
        try {
            String programName = program.substring(program.lastIndexOf("/") + 1, program.lastIndexOf("."));
            List<String> list = new ArrayList<String>();
            list.add("cmd.exe");
            list.add("/c");
            list.add("start");
            list.add("\"" + programName + "\"");
            list.add(server);
            ProcessBuilder pBuilder = new ProcessBuilder(list);
            pBuilder.start();
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}

  

java 执行 exe 文件

原文:https://www.cnblogs.com/han-guang-xue/p/13731735.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!