Java Kill Process killProcess(String name)

Here you can find the source of killProcess(String name)

Description

kill Process

License

Apache License

Declaration

public static void killProcess(String name) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void killProcess(String name) {
        try {/*  w  w  w . ja v a 2 s.co m*/
            ProcessBuilder processBuilder = new ProcessBuilder("taskkill ", "/IM", name);
            // processBuilder.directory(new File(image.getParent()));
            Process process = processBuilder.start();
            BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line = null;
            try {
                while ((line = br.readLine()) != null) {
                }
            } catch (Exception e) {
                e.printStackTrace();
                if (br != null) {
                    br.close();
                }
            }
        } catch (Exception e) {
        }
    }
}

Related

  1. killProcess(int port)
  2. killProcess(String processName)
  3. killProcess(String processName)
  4. killProcessesTree(String rootNamePart)
  5. killProcessNix(String pid)