1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import java.io.IOException; import java.util.Arrays; import java.util.concurrent.TimeUnit; public class Proceso { public static void main(String[] args) throws IOException { if (args.length <= 0) { System.err.println("Introducir programa a ejecutar"); System.exit(-1); } ProcessBuilder pb = new ProcessBuilder(args); try { Process process = pb.start(); TimeUnit.SECONDS.sleep(10); process.destroy(); System.out.println("El proceso " + Arrays.toString(args) + " acabó"); } catch(IOException ex) { System.err.println("Error"); System.exit(-1); } catch(InterruptedException ex) { System.err.println("Error"); System.exit(-1); } } } |