commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mishkin, Ernest" <>
Subject RE: ExecuteWatchdog does not really terminate the "hung" process?
Date Mon, 22 Jun 2009 14:11:16 GMT
Looks like my attachements got chopped somewhere along the way, so I'll
just paste the two files here since they're really short:

import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteException;
import org.apache.commons.exec.ExecuteWatchdog;
import org.apache.commons.exec.PumpStreamHandler;

public class ExecTest {

	public static void main(String[] args) throws Exception {
		File scriptFile = new File("sleep.bat");
		CommandLine cmdLine = new CommandLine(scriptFile);
		cmdLine.addArgument("10"); // sleep 10 secs
		System.out.println("Cmd line: " + cmdLine);
		DefaultExecutor executor = new DefaultExecutor();
		ExecuteWatchdog watchdog = new ExecuteWatchdog(2 *
1000); // allow process no more than 2 secs
		ByteArrayOutputStream baos = new
		executor.setStreamHandler(new PumpStreamHandler(baos));

		long startTime = System.currentTimeMillis();
		try {
		} catch (ExecuteException e) {
		System.out.println("Process completed in " +
(System.currentTimeMillis() - startTime) +" millis; below is its
		if (watchdog.killedProcess()) {
			System.out.println("Process timed out and was



ping -n %1 -w 1000

The information contained in this message is intended only for the recipient, and may be a
confidential attorney-client communication or may otherwise be privileged and confidential
and protected from disclosure. If the reader of this message is not the intended recipient,
or an employee or agent responsible for delivering this message to the intended recipient,
please be aware that any dissemination or copying of this communication is strictly prohibited.
If you have received this communication in error, please immediately notify us by replying
to the message and deleting it from your computer. The McGraw-Hill Companies, Inc. reserves
the right, subject to applicable local law, to monitor and review the content of any electronic
message or information sent to or from McGraw-Hill employee e-mail addresses without informing
the sender or recipient of the message.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message