链接:

https://www.cnblogs.com/pengpengzhang/p/8675740.html

https://blog.csdn.net/ZHANGHUI3239619/article/details/78808129

例:

// 启用exe客户端
@RequestMapping("/startUpXFExe")
@ResponseBody
public ResponseResult startUpXFExe(ModelMap map, HttpServletRequest request) {
ResponseResult responseResult = new ResponseResult(ResponseResult.FAILURECODE);
String exePathXF = SysConfigItemValue.getValue("exePathXF");//exe存放路径
if (StringUtils.isNotBlank(exePathXF)) {
String procName = "iflytek.Court.Client.exe";
String result = checkProcess(procName);//检查exe进程
if (result.isEmpty()) {
try {
//启动exe执行程序
Desktop.getDesktop().open(new File(exePathXF));
responseResult.setCode(ResponseResult.SUCCESSCODE);
//responseResult.setMsg("程序启动成功。");
} catch (Exception e) {
e.printStackTrace();
responseResult.setMsg("程序:" + exePathXF + "不存在!");
logger.error("程序:" + exePathXF + "不存在!");
}
}else {
responseResult.setMsg(result);
}
}
return responseResult;
} /**
* 检查进程是否存在,存在则杀死进程
* @param procName
*/
public String checkProcess(String procName) {
String result = "";
//判断是否存在进程
Boolean existProc = false;
BufferedReader bufferedReader = null;
try {
Process proc = Runtime.getRuntime().exec("tasklist -fi " + '"' + "imagename eq " + procName +'"');
bufferedReader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = null;
while ((line = bufferedReader.readLine()) != null) {
if (line.contains(procName)) {
existProc = true;//存在
}
}
} catch (Exception ex) {
result = "查询程序进程异常:"+ex.getMessage();
logger.error("查询程序进程异常:"+ex.getMessage());
return result;
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (Exception ex) {}
}
} // 存在,则先杀死该进程
if (existProc) {
BufferedReader br = null;
try {
if (StringUtils.isNotBlank(procName)) {
//执行cmd命令
String command = "taskkill /F /IM " + procName;
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("cmd /c " + command);
br = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
String line = null;
StringBuilder build = new StringBuilder();
while ((line = br.readLine()) != null) {
build.append(line);
}
}
} catch (Exception e) {
result = "关闭程序进程异常:"+e.getMessage();
logger.error("关闭程序进程异常:"+e.getMessage());
return result;
} finally {
if (br != null) {
try {
br.close();
} catch (Exception ex) {}
}
}
}
return result;
}

java-启动和关闭.exe程序的更多相关文章

  1. java在进程启动和关闭.exe程序

    /** * @desc 启动进程 * @author zp * @date 2018-3-29 */ public static void startProc(String processName) ...

  2. java实现可安装的exe程序

    java实现可安装的exe程序 通过编写Java代码,实现可安装的exe文件的一般思路: 1.在eclipse中创建java项目,然后编写Java代码,将编写好的Java项目导出一个.jar格式的ja ...

  3. Java编程打开运行exe程序

    String path = "notepad.exe"; //(C:\Program Files\Tencent\QQ\Bin\qq.exe) try { Runtime runt ...

  4. nohup npm start &启动之后关闭终端程序没有后台运行

    感谢:https://blog.csdn.net/nsj820/article/details/5862231 “在当shell中提示了nohup成功后,还需要按终端上键盘任意键退回到shell输入命 ...

  5. Tomcat学习笔记【2】--- Tomcat安装、环境变量配置、启动和关闭

    本文主要讲Tomcat的安装和配置. 一 Tomcat安装 1.1 下载 下载地址:http://tomcat.apache.org/ 1.2 安装 Tomcat是不需要安装的,解压压缩包即可. 在安 ...

  6. WPF 程序中启动和关闭外部.exe程序

    当需要在WPF程序启动时,启动另一外部程序(.exe程序)时,可以按照下面的例子来: C#后台代码如下: using System; using System.Collections.Generic; ...

  7. 查看程序是否启动或者关闭--比如查看Tomcat是否开启!直接用ps命令查看进程就行了啊

    1.查看程序是否启动或者关闭--比如查看Tomcat是否开启!直接用ps命令查看进程就行了啊 2.Tomcat服务器和虚拟机的关系,Tomcat启动运行过程要调用系统环境变量的java_home啊,J ...

  8. Android adb.exe程序启动不起来,如何处理

    经常遇到 Please ensure that adb is correctly located at 'D:\java\sdk\platform-tools\adb.exe' and can be ...

  9. 【解决】应用程序无法正常启动(0xc000007b)。请单击“确定”关闭应用程序。

    换了SSD硬盘,装了Windows 7 SP1 x64的系统.用了一段时间,突然一天有些软件打不开了.弹出下面的提示 应用程序无法正常启动(0xc000007b).请单击“确定”关闭应用程序.第一时间 ...

随机推荐

  1. webForm TO MVC

     

  2. HTTP 错误 500.19 - Internal Server Error v4.0.30319

    1 打开运行,输入cmd进入到命令提示符窗口.2 进入到C:\Windows\Microsoft.NET\Framework\v4.0.30319 目录.3 输入aspnet_regiis.exe - ...

  3. 使用Python-Libvirt GUI 实现KVM 虚拟机 界面化管理

    一.KVM环境的搭建 1.安装VMware(略) 2.在VMware中安装Linux系统(略,Ubuntu16.04) 打开支持虚拟化 网络选择桥接模式 3.安装qemu apt-get instal ...

  4. 【转】 SQL - 生成指定范围内的随机数

    DECLARE @Result INT DECLARE @Upper INT DECLARE @Lower INT SET @Lower = 1 SET @Upper = 10 SELECT @Res ...

  5. TCP/IP协议网络编程以及UDP和TCP之传输协议

    1.什么是TCP/IP协议? 网络编程协议有很多,目前应用最广泛的是TCP/IP协议(Transmission Control Protocal/Internet Protoal 传输控制协议/英特网 ...

  6. [HDU6146]Pokémon GO

    Problem 有一个2n的方格矩阵 在一个格子上可以往旁边8个方向走(如果有格子),求有多少方案把2n走完 Solution 我们用Fi表示从一个角出发走遍所有格子回到这一列另外一点的方案数 显然, ...

  7. bootstrap validator 出现Maximum call stack size exceeded

    如果用 c# 里面用的是 taghelper 的控件,有可能造成 Maximum call stack size exceeded bootstrap validator  必须是继承  bootst ...

  8. JAVA学习笔记系列3-JVM、JRE和JDK的区别

    JVM(Java Virtual Machine)就是一个虚拟的用于执行bytecode字节码的“虚拟计算机”.它和os打交道 JRE(Java Runtime Environment)包含:Java ...

  9. mod_fcgid FcgidMaxRequestLen 131072 问题

    mod_fcgid: HTTP request length 136136 (so far) exceeds MaxRequestLen (131072)   原来是fastcgi模式下的设置问题,需 ...

  10. 获取Ueditor里面的图片列表,地址绝对化

    /**     * 内容中图片地址转成绝对地址     * @param $content     * @return mixed     */    private function imgUrl( ...