Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 19174 invoked from network); 23 Apr 2008 13:49:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 23 Apr 2008 13:49:08 -0000 Received: (qmail 10161 invoked by uid 500); 23 Apr 2008 13:49:04 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 10093 invoked by uid 500); 23 Apr 2008 13:49:03 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list user@commons.apache.org Delivered-To: moderator for user@commons.apache.org Received: (qmail 13798 invoked by uid 99); 23 Apr 2008 08:36:40 -0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of sgoeschl@gmx.at designates 213.165.64.20 as permitted sender) X-Authenticated: #35915548 X-Provags-ID: V01U2FsdGVkX18cjfl3GEUcsYPvIABNlGdat5ILqL9AHZJdfwmeSM +YRi5sXg8MzlbI Message-ID: <480EF4EF.5000806@gmx.at> Date: Wed, 23 Apr 2008 10:35:59 +0200 From: Siegfried Goeschl Reply-To: sgoeschl@gmx.at User-Agent: Thunderbird 2.0.0.12 (Macintosh/20080213) MIME-Version: 1.0 To: Jakarta Commons Users List Subject: Re: [commons-exec] Watchdog References: In-Reply-To: X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 8bit X-Y-GMX-Trusted: 0 X-Virus-Checked: Checked by ClamAV on apache.org Hi Tino, +) I have a look at it tonight .... +) in general you won't be able to kill the 'ping' process anyway under Windows - see http://bugs.sun.com/bugdatabase/view_bug.do;:YfiG?bug_id=4770092 Cheers, Siegfried Goeschl Tino Sch�llhorn wrote: > Hi, > > I have a problem concerning commons-exec when using the timeouts with > a watchdog. The test-cases are running fine (Windows Vista, JDK 1.5.x) > > I tried to simplify the usage of commons-exec because in our use-case > we often need a very simple case. > > So I have a class ExecUtils which tries to hide the complexity of many > (necessary) details. It mainly has a static method > ExecUtils.exec(String cmd, int timeout) which should run an command in > a shell and terminate the command if necessary. > > But - in my simple test-case the timout does not occur. What am I > missing? > > I am glad for your help. > > Cheers > Tino > > > > ---------------------- > --- TEST > ---------------------- > public void testTimeoutCommand() { > System.out.println("*** testTimeoutCommand.begin"); > > // 100 Pings senden, aber nach 5 Sekunden abbrechen. > > String cmd = "ping localhost -n 10000 -w 1000"; > > ExecUtils.Result r = ExecUtils.exec(cmd, 5000); > > assertTrue("Es muss ein Timeout auftreten!", r.hasTimeout()); > > System.err.println("result: " + r); > > > System.out.println("*** testTimeoutCommand.end"); > } > > > > > ---------------------- > --- Code of ExecUtils > ---------------------- > > public class ExecUtils { > > public static class Result { > private String out; > private String err; > private int exitValue; > private boolean timeout; > private Exception exception; > > public String getStdOut() { > return out; > } > > public String getStdErr() { > return err; > } > > public int getExitValue() { > return exitValue; > } > > public boolean hasTimeout() { > return timeout; > } > > public Exception getException() { > return exception; > } > > } > > public static Result exec(String cmdLine) { > return exec(cmdLine, Integer.MAX_VALUE); > } > > public static Result exec(String cmdLine, int timeout) { > DefaultExecutor executor = new DefaultExecutor(); > > ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); > executor.setWatchdog(watchdog); > > ByteArrayOutputStream baosOut = new ByteArrayOutputStream(); > ByteArrayOutputStream baosErr = new ByteArrayOutputStream(); > > PumpStreamHandler streamHandler = new > PumpStreamHandler(baosOut, baosErr); > //PumpStreamHandler streamHandler = new PumpStreamHandler(); > executor.setStreamHandler(streamHandler); > > // this is simplified > CommandLine commandLine = "cmd.exe /c " + cmdLine; > > Result res = new Result(); > try { > > res.exitValue = executor.execute(commandLine); > > } catch (Exception x) { > res.exception = x; > } finally { > res.out = new String(baosOut.toByteArray()); > res.err = new String(baosErr.toByteArray()); > res.timeout = watchdog.killedProcess(); > } > > return res; > } > } > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org > For additional commands, e-mail: user-help@commons.apache.org > > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org