+ cmdToUse = cmd;
+
+ CommandLine commandLine = null;
+
+ // Which command definition to use
+ if (commandToUse == null && cmdToUse == null)
+ throw new SlcException("Please specify a command.");
+ else if (commandToUse != null && cmdToUse != null)
+ throw new SlcException(
+ "Specify the command either as a line or as a list.");
+ else if (cmdToUse != null) {
+ commandLine = CommandLine.parse(cmdToUse);
+ } else if (commandToUse != null) {
+ if (commandToUse.size() == 0)
+ throw new SlcException("Command line is empty.");
+
+ commandLine = new CommandLine(commandToUse.get(0).toString());
+
+ for (int i = 1; i < commandToUse.size(); i++) {
+ if (log.isTraceEnabled())
+ log.debug(commandToUse.get(i));
+ commandLine.addArgument(commandToUse.get(i).toString());
+ }
+ } else {
+ // all cases covered previously
+ throw new UnsupportedException();
+ }
+
+ if (generateScript != null) {
+ File scriptFile = new File(getExecDirToUse() + File.separator
+ + generateScript);
+ try {
+ FileUtils.writeStringToFile(scriptFile,
+ (osConsole != null ? osConsole + " " : "")
+ + commandLine.toString());
+ } catch (IOException e) {
+ throw new SlcException("Could not generate script "
+ + scriptFile, e);
+ }
+ commandLine = new CommandLine(scriptFile);
+ } else {
+ if (osConsole != null)
+ commandLine = CommandLine.parse(osConsole + " "
+ + commandLine.toString());
+ }
+
+ return commandLine;
+ }
+
+ /**
+ * Creates a {@link PumpStreamHandler} which redirects streams to the custom
+ * logging mechanism.
+ */
+ protected ExecuteStreamHandler createExecuteStreamHandler(
+ final Writer stdOutWriter, final Writer stdErrWriter) {
+ // Log writers
+
+ PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(
+ new LogOutputStream() {
+ protected void processLine(String line, int level) {
+ log(stdOutLogLevel, line);
+ if (stdOutWriter != null)
+ appendLineToFile(stdOutWriter, line);
+ }
+ }, new LogOutputStream() {
+ protected void processLine(String line, int level) {
+ log(stdErrLogLevel, line);
+ if (stdErrWriter != null)
+ appendLineToFile(stdErrWriter, line);
+ }
+ }, null);
+ return pumpStreamHandler;