Author: sgoeschl
Date: Wed Jan 23 13:22:59 2008
New Revision: 614674
URL: http://svn.apache.org/viewvc?rev=614674&view=rev
Log:
+) Updated javadocs
+) throw an IOException if closing the stream fail
Modified:
commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/DefaultExecutor.java
Modified:
commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/DefaultExecutor.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/DefaultExecutor.java?rev=614674&r1=614673&r2=614674&view=diff
==============================================================================
---
commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/DefaultExecutor.java
(original)
+++
commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/DefaultExecutor.java
Wed Jan 23 13:22:59 2008
@@ -24,7 +24,26 @@
import org.apache.commons.exec.launcher.CommandLauncherFactory;
/**
- *
+ * The default class to start a subprocess. The implementation
+ * allows to
+ * <ul>
+ * <li>set a current working directory for the subprocess</li>
+ * <li>provide a set of environment variables passed to the subprocess</li>
+ * <li>capture the subprocess output of stdout and stderr using an
ExecuteStreamHandler</li>
+ * <li>kill long-running processes using an ExecuteWatchdog</li>
+ * <li>define a set of expected exit values</li>
+ * <li>terminate any started processes when the main process is terminating
using a ProcessDestroyer</li>
+ * </ul>
+ *
+ * The following example shows the basic usage:
+ *
+ * <pre>
+ * Executor exec = new DefaultExecutor();
+ * CommandLine cl = new CommandLine("ls -l");
+ * int exitvalue = exec.execute(cl);
+ * </pre>
+ *
+ *
*/
public class DefaultExecutor implements Executor {
@@ -249,27 +268,49 @@
/**
* Close the streams belonging to the given Process.
*
- * @param process
- * the <CODE>Process</CODE>.
+ * @param process the <CODE>Process</CODE>.
+ * @throws IOException closing one of the three streams failed
*/
- private void closeStreams(final Process process) {
+ private void closeStreams(final Process process) throws IOException {
+
+ IOException caught = null;
+
try {
process.getInputStream().close();
- } catch (IOException eyeOhEx) {
- // ignore error
}
+ catch(IOException e) {
+ caught = e;
+ }
+
try {
process.getOutputStream().close();
- } catch (IOException eyeOhEx) {
- // ignore error
}
+ catch(IOException e) {
+ caught = e;
+ }
+
try {
process.getErrorStream().close();
- } catch (IOException eyeOhEx) {
- // ignore error
+ }
+ catch(IOException e) {
+ caught = e;
+ }
+
+ if(caught != null) {
+ throw caught;
}
}
+ /**
+ * Execute an internal process.
+ *
+ * @param command the command to execute
+ * @param environment the execution enviroment
+ * @param dir the working directory
+ * @param streams process the streams (in, out, err) of the process
+ * @return the exit code of the process
+ * @throws IOException executing the process failed
+ */
private int executeInternal(final CommandLine command, final Map
environment,
final File dir, final ExecuteStreamHandler streams) throws
IOException {
@@ -312,7 +353,6 @@
try {
watchdog.checkException();
} catch (Exception e) {
- // TODO: include cause
throw new IOException(e.getMessage());
}
}