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; } } }
原文:https://www.cnblogs.com/han-guang-xue/p/13731735.html