шпаргалки
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

41 lines
1.1 KiB

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package lang;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author (C)Y.D.Zakovryashin, 14.11.2022
*/
public class DemoRuntime {
private String cmd = "calc.exe";
public static void main(String[] args) {
new DemoRuntime().run();
}
public void run() {
Runtime r = Runtime.getRuntime();
try {
Process p = r.exec(cmd);
p.waitFor(5, TimeUnit.SECONDS);
if (p.isAlive()) {
System.out.println("Process is alive");
p.destroyForcibly();
} else {
System.out.println("Process is done");
}
System.out.println("Exit code: " + p.exitValue());
} catch (IOException | InterruptedException ex) {
System.out.println("Error: " + ex.getMessage());
}
}
}