Here you can find the source of execProcess(String[] cmdline, final long timeout)
Parameter | Description |
---|---|
cmdline | a parameter |
timeout | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
private static int execProcess(String[] cmdline, final long timeout) throws IOException
//package com.java2s; /**/* w ww . j av a 2 s . c om*/ * Aptana Studio * Copyright (c) 2005-2011 by Appcelerator, Inc. All Rights Reserved. * Licensed under the terms of the GNU Public License (GPL) v3 (with exceptions). * Please see the license.html included with this distribution for details. * Any modifications to this file must keep this entire header intact. */ import java.io.IOException; public class Main { /** * execProcess * * @param cmdline * @param timeout * @return int * @throws IOException */ private static int execProcess(String[] cmdline, final long timeout) throws IOException { Process process = Runtime.getRuntime().exec(cmdline); final Thread thread = Thread.currentThread(); Thread waitTimeout = new Thread() { public void run() { try { Thread.sleep(timeout); thread.interrupt(); } catch (InterruptedException ignore) { } } }; int exitcode = 0; if (timeout != -1) { try { waitTimeout.start(); exitcode = process.waitFor(); waitTimeout.interrupt(); } catch (InterruptedException e) { Thread.interrupted(); } process.destroy(); } try { exitcode = process.waitFor(); } catch (InterruptedException e) { } return exitcode; } }