/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/**
* Wrapper to Java Process API
*
* @author Emilio Monti - emilmont@gmail.com
*/
public class Executor {
private byte[] stdout;
private byte[] stderr;
/**
* Create a new instance of the Executor.
* @param cmd An array containing the command to execute
*/
}
/**
* Create a new instance of the Executor.
* @param cmdList A list containing the command to execute
*/
}
/**
* Create a new instance of the Executor
* @param cmdList A list containing the command to execute
* @param workingDirectory The directory the process should have as the
* working directory
*/
this.workingDirectory = workingDirectory;
}
/**
* Execute the command and collect the output. All exceptions will be
* logged.
*
* @return The exit code of the process
*/
public int exec() {
return exec(true);
}
/**
* Execute the command and collect the output
*
* @param reportExceptions Should exceptions be added to the log or not
* @return The exit code of the process
*/
return ret;
}
/**
* Execute the command and collect the output
*
* @param reportExceptions Should exceptions be added to the log or not
* @param handler The handler to handle data from standard output
* @return The exit code of the process
*/
int ret = -1;
if (workingDirectory != null) {
}
}
"Executing command {0} in directory {1}",
new Object[] {
});
try {
public void run() {
try {
} catch (IOException ex) {
if (reportExceptions) {
"Error during process pipe listening", ex);
}
}
}
});
} catch (IOException e) {
if (reportExceptions) {
}
} catch (InterruptedException e) {
if (reportExceptions) {
}
} finally {
try {
}
} catch (IllegalThreadStateException e) {
}
}
.append(" in directory ");
} else {
}
} else {
}
}
}
return ret;
}
/**
* Get the output from the process as a string.
*
* @return The output from the process
*/
}
return ret;
}
/**
* Get a reader to read the output from the process
*
* @return A reader reading the process output
*/
return new InputStreamReader(getOutputStream());
}
/**
* Get an input stream read the output from the process
*
* @return A reader reading the process output
*/
return new ByteArrayInputStream(stdout);
}
/**
* Get the output from the process written to the error stream as a string.
*
* @return The error output from the process
*/
}
return ret;
}
/**
* Get a reader to read the output the process wrote to the error stream.
*
* @return A reader reading the process error stream
*/
return new InputStreamReader(getErrorStream());
}
/**
* Get an inputstreamto read the output the process wrote to the error stream.
*
* @return An inputstream for reading the process error stream
*/
return new ByteArrayInputStream(stderr);
}
/**
* You should use the StreamHandler interface if you would like to process
* the output from a process while it is running
*/
public static interface StreamHandler {
/**
* Process the data in the stream. The processStream function is
* called _once_ during the lifetime of the process, and you should
* process all of the input you want before returning from the function.
*
* @param in The InputStream containing the data
* @throws java.io.IOException
*/
}
public byte[] getBytes() {
return bytes.toByteArray();
}
byte[] buffer = new byte[8092];
int len;
if (len > 0) {
}
}
}
}
public static void registerErrorHandler() {
+ e.getMessage(), e);
}
});
}
}
}