Java program to execute taskkill command to kill ping

This java program kills all the ping.exe processes which are running on the system.

Note: “ping.exe” in below code can be changed to any running process to kill it.

Please click here to see various options of taskkill command options.

Java program to execute taskkill command to kill ping:

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

public class killPing {

	public static void main(String[] args) throws IOException {
		Process pr;
		try {
			pr = Runtime.getRuntime().exec("taskkill /f /im ping.exe");
			BufferedReader reader = new BufferedReader(new InputStreamReader(pr.getInputStream()));
			String line = reader.readLine();
			while (line != null) {
				System.out.println(line);
				line = reader.readLine();
			}
		}catch(Exception e){
			System.out.println(e);
		}
	}
}

Leave a Reply

Your email address will not be published. Required fields are marked *