04
Sep

kill a process via java program

Following code snippet can be used to kill all running instances of Internet Explorer

import java.io.IOException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class RerunAttemp {

@Test
public void killIEBrowser() {
WebDriver driver = new FirefoxDriver();
driver.get(“http://www.google.co.in”);

try {
Process process = Runtime.getRuntime().exec(“taskkill /F /IM iexplore.exe”);
} catch (IOException e) {
e.printStackTrace();
}

driver.quit();
}
}

We can add necessary logistics to handle if IE is running before killing a process.