46 lines
1.8 KiB
Java
46 lines
1.8 KiB
Java
|
|
package org.example.test;
|
|||
|
|
|
|||
|
|
import java.io.BufferedReader;
|
|||
|
|
import java.io.InputStreamReader;
|
|||
|
|
|
|||
|
|
public class ExeMain {
|
|||
|
|
public static void main(String[] args) {
|
|||
|
|
//需要传入的参数(ps: 多个参数用空格隔开)
|
|||
|
|
// String paras = " --task C:\\Users\\Admin\\.cesiumlab\\tasks\\terrain_99254c80b1ef11ea8edfe728504fc83a.json --taskserver tcp://127.0.0.1:9001 --taskname 99254c80b1ef11ea8edfe728504fc83a --log_dir C:\\Users\\Admin\\.cesiumlab\\logs";
|
|||
|
|
String paras = "";
|
|||
|
|
//调用的exe可执行文件(ps: 调用可执行文件和参数拼接必须要用空格隔开)
|
|||
|
|
String cmd = "E:\\code\\contour2dem.gui\\contour2dem.gui.exe" + paras;
|
|||
|
|
|
|||
|
|
openExe(cmd);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
public static void openExe(String cmd) {
|
|||
|
|
BufferedReader br = null;
|
|||
|
|
BufferedReader brError = null;
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
//执行exe cmd可以为字符串(exe存放路径)也可为数组,调用exe时需要传入参数时,可以传数组调用(参数有顺序要求)
|
|||
|
|
Process p = Runtime.getRuntime().exec(cmd);
|
|||
|
|
String line = null;
|
|||
|
|
//获得子进程的输入流。
|
|||
|
|
br = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
|||
|
|
//获得子进程的错误流。
|
|||
|
|
brError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
|
|||
|
|
while ((line = br.readLine()) != null || (line = brError.readLine()) != null) {
|
|||
|
|
//输出exe输出的信息以及错误信息
|
|||
|
|
System.out.println(line);
|
|||
|
|
}
|
|||
|
|
} catch (Exception e) {
|
|||
|
|
e.printStackTrace();
|
|||
|
|
} finally {
|
|||
|
|
if (br != null) {
|
|||
|
|
try {
|
|||
|
|
br.close();
|
|||
|
|
} catch (Exception e) {
|
|||
|
|
e.printStackTrace();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|