Example usage for java.lang Process getErrorStream

List of usage examples for java.lang Process getErrorStream

Introduction

In this page you can find the example usage for java.lang Process getErrorStream.

Prototype

public abstract InputStream getErrorStream();

Source Link

Document

Returns the input stream connected to the error output of the process.

Usage

From source file:de.fosd.jdime.strategy.LinebasedStrategy.java

/**
 * This line-based <code>merge</code> method uses the merging routine of
 * the external tool <code>git</code>.
 * <p>/*ww w .  jav  a2s.  c  o m*/
 * Basically, the input <code>FileArtifacts</code> are passed as arguments to
 * `git merge-file -q -p`.
 * <p>
 * In a common run, the number of processed lines of code, the number of
 * conflicting situations, and the number of conflicting lines of code will
 * be counted. Empty lines and comments are skipped to keep
 * <code>MergeStrategies</code> comparable, as JDime does (in its current
 * implementation) not respect comments.
 * <p>
 * In case of a performance benchmark, the output is simply ignored for the
 * sake of speed, and the merge will be run the specified amount of times,
 * aiming to allow the computation of a reasonable mean runtime.
 *
 * @param operation <code>MergeOperation</code> that is executed by this strategy
 * @param context <code>MergeContext</code> that is used to retrieve environmental parameters
 *
 * @throws IOException
 * @throws InterruptedException
 */
@Override
public final void merge(final MergeOperation<FileArtifact> operation, final MergeContext context)
        throws IOException, InterruptedException {

    assert (operation != null);
    assert (context != null);

    MergeTriple<FileArtifact> triple = operation.getMergeTriple();
    assert (triple != null);
    assert (triple.isValid()) : "The merge triple is not valid!";
    assert (triple.getLeft() instanceof FileArtifact);
    assert (triple.getBase() instanceof FileArtifact);
    assert (triple.getRight() instanceof FileArtifact);
    assert (triple.getLeft().exists() && !triple.getLeft().isDirectory());
    assert ((triple.getBase().exists() && !triple.getBase().isDirectory()) || triple.getBase().isEmptyDummy());
    assert (triple.getRight().exists() && !triple.getRight().isDirectory());

    context.resetStreams();
    FileArtifact target = null;

    if (operation.getTarget() != null) {
        assert (operation.getTarget() instanceof FileArtifact);
        target = operation.getTarget();
        assert (!target.exists() || target.isEmpty()) : "Would be overwritten: " + target;
    }

    List<String> cmd = new ArrayList<>();
    cmd.add(BASECMD);
    cmd.addAll(Arrays.asList(BASEARGS));

    for (FileArtifact file : triple.getList()) {
        cmd.add(file.getPath());
    }

    ProcessBuilder pb = new ProcessBuilder(cmd);
    ArrayList<Long> runtimes = new ArrayList<>();
    int conflicts = 0;
    int loc = 0;
    int cloc = 0;

    // launch the merge process by invoking GNU merge (rcs has to be
    // installed)
    LOG.debug("Running external command: " + StringUtils.join(cmd, " "));

    for (int i = 0; i < context.getBenchmarkRuns() + 1 && (i == 0 || context.isBenchmark()); i++) {
        long cmdStart = System.currentTimeMillis();
        Process pr = pb.start();

        if (i == 0 && (!context.isBenchmark() || context.hasStats())) {
            // process input stream
            BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
            boolean conflict = false;
            boolean comment = false;

            int tmp = 0;
            String line;
            while ((line = buf.readLine()) != null) {
                context.appendLine(line);

                if (context.hasStats()) {
                    if (line.matches("^$") || line.matches("^\\s*$") || line.matches("^\\s*//.*$")) {
                        // skip empty lines and single line comments
                        continue;
                    } else if (line.matches("^\\s*/\\*.*")) {
                        if (line.matches("^\\s*/\\*.*?\\*/")) {
                            // one line comment
                            continue;
                        } else {
                            // starting block comment
                            comment = true;
                            continue;
                        }
                    } else if (line.matches("^.*?\\*/")) {
                        // ending block comment
                        comment = false;
                        continue;
                    }
                    if (line.matches("^\\s*<<<<<<<.*")) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("CONFLICT in " + triple);
                        }
                        conflict = true;
                        comment = false;
                        tmp = cloc;
                        conflicts++;
                    } else if (line.matches("^\\s*=======.*")) {
                        comment = false;
                    } else if (line.matches("^\\s*>>>>>>>.*")) {
                        conflict = false;
                        comment = false;
                        if (tmp == cloc) {
                            // only conflicting comments or empty lines
                            conflicts--;
                        }
                    } else {
                        loc++;
                        if (conflict && !comment) {
                            cloc++;
                        }
                    }
                }
            }

            buf.close();

            // process error stream
            buf = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
            while ((line = buf.readLine()) != null) {
                if (i == 0 && (!context.isBenchmark() || context.hasStats())) {
                    context.appendErrorLine(line);
                }
            }

            buf.close();
        }
        pr.getInputStream().close();
        pr.getErrorStream().close();
        pr.getOutputStream().close();

        pr.waitFor();

        long runtime = System.currentTimeMillis() - cmdStart;
        runtimes.add(runtime);

        if (LOG.isInfoEnabled() && context.isBenchmark() && context.hasStats()) {
            if (i == 0) {
                LOG.info("Initial run: " + runtime + " ms");
            } else {
                LOG.info("Run " + i + " of " + context.getBenchmarkRuns() + ": " + runtime + " ms");
            }
        }
    }

    if (context.isBenchmark() && runtimes.size() > 1) {
        // remove first run as it took way longer due to all the counting
        runtimes.remove(0);
    }

    Long runtime = MergeContext.median(runtimes);
    LOG.debug("Linebased merge time was " + runtime + " ms.");

    if (context.hasErrors()) {
        LOG.fatal("Errors occured while calling '" + cmd + "')");
        System.err.println(context.getStdErr());
    }

    // write output
    if (target != null) {
        assert (target.exists());
        target.write(context.getStdIn());
    }

    // add statistical data to context
    if (context.hasStats()) {
        assert (cloc <= loc);

        Stats stats = context.getStats();
        StatsElement linesElement = stats.getElement("lines");
        assert (linesElement != null);
        StatsElement newElement = new StatsElement();
        newElement.setMerged(loc);
        newElement.setConflicting(cloc);
        linesElement.addStatsElement(newElement);

        if (conflicts > 0) {
            assert (cloc > 0);
            stats.addConflicts(conflicts);
            StatsElement filesElement = stats.getElement("files");
            assert (filesElement != null);
            filesElement.incrementConflicting();
        } else {
            assert (cloc == 0);
        }

        stats.increaseRuntime(runtime);

        MergeTripleStats scenariostats = new MergeTripleStats(triple, conflicts, cloc, loc, runtime, null, null,
                null);
        stats.addScenarioStats(scenariostats);
    }
}

From source file:marytts.tools.voiceimport.HTKLabeler.java

/**
 * create phone master label file (Not used?)
 * @throws Exception//from   www.ja  v a 2  s .  c om
 */
private void createPhoneMLFile() throws Exception {
    String hled = getProp(HTKDIR) + File.separator + "HLEd";
    File htkFile = new File(hled);
    if (!htkFile.exists()) {
        throw new RuntimeException("File " + htkFile.getAbsolutePath() + " does not exist");
    }
    String dict = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.dict";
    String phoneMLF = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.phones.mlf";
    String wordsMLF = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.words.mlf";
    String mkphoneLED = getProp(HTDIR) + File.separator + "config" + File.separator + "mkphone0.led";

    Runtime rtime = Runtime.getRuntime();
    //get a shell
    Process process = rtime.exec("/bin/bash");
    //get an output stream to write to the shell
    PrintWriter pw = new PrintWriter(new OutputStreamWriter(process.getOutputStream()));
    System.out.println("( " + hled + " -l '*' -d " + dict + " -i " + phoneMLF + " " + mkphoneLED + " "
            + wordsMLF + "; exit )\n");

    pw.print("( " + hled + " -l '*' -d " + dict + " -i " + phoneMLF + " " + mkphoneLED + " " + wordsMLF
    //+"; "
            + "; exit )\n");
    pw.flush();
    //shut down
    pw.close();
    process.waitFor();
    // check exit value
    if (process.exitValue() != 0) {
        BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
        throw new MaryConfigurationException(errorReader.readLine());
    }

}

From source file:marytts.tools.voiceimport.HTKLabeler.java

/**
* Setup the HTK directory//from   w  w  w. j  a  va2 s  . c  o  m
* @throws IOException, InterruptedException
  * @throws MaryConfigurationException 
*/
private void setup() throws IOException, InterruptedException, MaryConfigurationException {

    htk.mkdir();
    File lab = new File(htk.getAbsolutePath() + "/lab");
    //call setup of HTK in this directory
    Runtime rtime = Runtime.getRuntime();
    //get a shell
    Process process = rtime.exec("/bin/bash");
    //get an output stream to write to the shell
    PrintWriter pw = new PrintWriter(new OutputStreamWriter(process.getOutputStream()));
    //go to htk directory and setup Directory Structure 
    pw.print("( cd " + htk.getAbsolutePath() + "; mkdir -p hmm" + "; mkdir -p etc" + "; mkdir -p feat"
            + "; mkdir -p config" + "; mkdir -p lab" + "; mkdir -p htk-full/lab" + "; mkdir -p htk-full/wrd"
            + "; exit )\n");
    pw.flush();
    //shut down
    pw.close();
    process.waitFor();
    // check exit value
    if (process.exitValue() != 0) {
        BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
        throw new MaryConfigurationException(errorReader.readLine());
    }

    // TODO: temporary: at the moment fix path to load the dictionary
    lexicon = new FSTLookup(new FileInputStream(
            "/home/fabio/voice_building_5_0/marytts-it/marytts-lang-it/src/main/resources/marytts/language/it/lexicon/it_lexicon.fst"),
            "it_lexicon.fst");

    /*  System.out.print("Starting builtin MARY TTS...");
    Mary.startup();
    System.out.println(" MARY TTS started.");
            
    e poi 
    */

}

From source file:marytts.tools.voiceimport.HTKLabeler.java

private void saveHTKWordDictionary() throws Exception {

    String dict0 = outputDir + File.separator + "htk.words0.dict";
    String dict = outputDir + File.separator + "htk.words.dict";
    PrintWriter wordDictOut = new PrintWriter(new FileOutputStream(new File(dict0)));

    HTKdictionary.add("sil sil");
    HTKdictionary.add("ssil ssil");
    HTKdictionary.add("sp sp");

    Iterator<String> itr = HTKdictionary.iterator();
    while (itr.hasNext()) {
        wordDictOut.println(itr.next());
    }/*from   ww w. ja va 2  s. c o  m*/

    wordDictOut.flush();
    wordDictOut.close();

    String fileded = getProp(HTDIR) + File.separator + "config" + File.separator + "dict.ded";
    PrintWriter dedDictOut = new PrintWriter(new FileOutputStream(new File(fileded)));

    dedDictOut.println("AS sp");
    dedDictOut.println("MP sil sil sp");
    dedDictOut.println("MP ssil ssil sp");
    dedDictOut.println("MP sp sp sp");

    dedDictOut.flush();
    dedDictOut.close();

    Runtime rtime = Runtime.getRuntime();
    //get a shell
    Process process = rtime.exec("/bin/bash");
    //get an output stream to write to the shell

    //when no sp use (-m)!

    String hdman = getProp(HTKDIR) + File.separator + "HDMan";

    PrintWriter pw = new PrintWriter(new OutputStreamWriter(process.getOutputStream()));

    String cmd = "( cd " + getProp(HTDIR) + "; " + hdman + " -g " + fileded + " " + dict + " " + dict0
            + "; exit )\n";

    System.out.println(cmd);
    pw.println(cmd);

    pw.flush();
    //shut down
    pw.close();
    process.waitFor();
    // check exit value
    if (process.exitValue() != 0) {
        BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
        throw new MaryConfigurationException(errorReader.readLine());
    }
}

From source file:marytts.tools.voiceimport.HTKLabeler.java

/**
 * Create HMMs for each phone from Global HMMs 
 * @throws Exception/*from   www  .  ja  v a 2s .  c  om*/
 */
private void createTrainFile() throws Exception {

    String script;
    String hmmDir = getProp(HTDIR) + File.separator + "hmm" + File.separator;

    /**TODO:
     * Replace below 'gawk' script with Java method.
     */

    script = "mkdir hmm/hmm0\n" + "head -3 hmm/hmm-dummy/htk > hmm/hmm0/hmmdefs\n"
            + "for s in `cat etc/htk.phone.list`\n" + "do\n" + "echo \"~h \\\"$s\\\"\" >> hmm/hmm0/hmmdefs\n"
            + "gawk '/BEGINHMM/,/ENDHMM/ { print $0 }' hmm/hmm-dummy/htk >> hmm/hmm0/hmmdefs\n" + "done\n";
    // creating list of training files
    File file = new File(getProp(HTDIR) + File.separator + "etc" + File.separator + "htkTrainScript.sh");
    PrintWriter pw = new PrintWriter(new FileWriter(file));
    pw.println(script);
    pw.flush();
    pw.close();

    Runtime rtime = Runtime.getRuntime();
    //get a shell
    Process process = rtime.exec("/bin/bash");
    //get an output stream to write to the shell
    pw = new PrintWriter(new OutputStreamWriter(process.getOutputStream()));

    System.out.println("( cd " + getProp(HTDIR) + "; sh etc" + File.separator + "htkTrainScript.sh"
            + " > log_htkTrainScript.txt" + "; exit )\n");
    pw.print("( cd " + getProp(HTDIR) + "; sh etc" + File.separator + "htkTrainScript.sh"
            + " > log_htkTrainScript.txt" + "; exit )\n");

    pw.flush();
    //shut down
    pw.close();
    process.waitFor();
    // check exit value
    if (process.exitValue() != 0) {
        BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
        throw new MaryConfigurationException(errorReader.readLine());
    }

    PrintWriter macroFile = new PrintWriter(
            new FileOutputStream(new File(hmmDir + "hmm0" + File.separator + "macros")));
    macroFile.println("~o\n" + "<VecSize> 13\n" + "<" + Train_FEAT + ">");
    macroFile.println(
            FileUtils.getFileAsString(new File(hmmDir + "hmm-dummy" + File.separator + "vFloors"), "ASCII"));
    macroFile.flush();
    macroFile.close();

}

From source file:marytts.tools.voiceimport.HTKLabeler.java

/**
 * Feature Extraction for HTK Training /*  w w  w  . ja  v  a  2 s .  co  m*/
 * @throws Exception
 */
private void featureExtraction() throws Exception {

    String hcopy = getProp(HTKDIR) + File.separator + "HCopy";
    File htkFile = new File(hcopy);
    if (!htkFile.exists()) {
        throw new RuntimeException("File " + htkFile.getAbsolutePath() + " does not exist");
    }
    String configFile = getProp(HTDIR) + File.separator + "config" + File.separator + "featEx.conf";
    String listFile = getProp(HTDIR) + File.separator + "etc" + File.separator + "featEx.list";
    Runtime rtime = Runtime.getRuntime();
    //get a shell
    Process process = rtime.exec("/bin/bash");
    //get an output stream to write to the shell
    PrintWriter pw = new PrintWriter(new OutputStreamWriter(process.getOutputStream()));
    System.out.println("( cd " + getProp(HTDIR) + "; " + hcopy + " -T 1 -C " + configFile + " -S " + listFile
            + " > log_featureExtraction.txt" + "; exit )\n");
    pw.print("( cd " + getProp(HTDIR) + "; " + hcopy + " -T 1 -C " + configFile + " -S " + listFile
            + " > log_featureExtraction.txt" + "; exit )\n");
    pw.flush();
    //shut down
    pw.close();
    process.waitFor();
    // check exit value
    if (process.exitValue() != 0) {
        BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
        throw new MaryConfigurationException(errorReader.readLine());
    }
}

From source file:de.unibi.techfak.bibiserv.BiBiTools.java

/**
 * chmodDir() sets perms of a dir as defined in bibiprops.
 *
 * @return boolean true if successfully exec of chmod is succesful, doesnt
 * matter if changed or not, false on failure
 *//*from   w w w . ja  va2  s  . c  o m*/
private boolean chmodDir(File dir) {
    Runtime runtime = Runtime.getRuntime();
    try {
        String chmodCmd = properties.getProperty("chmod.bin") + " " + properties.getProperty("chmod.param")
                + " " + dir.toString();
        Process process = runtime.exec(chmodCmd);
        if (process.waitFor() != 0) {
            log.error("could not chmod '" + chmodCmd + "'!\n "
                    + i2s(new InputStreamReader(process.getErrorStream())));

            process.getErrorStream().close();
            return false;
        }

        log.debug("chmod for dir '" + dir.toString() + "' done: " + dir.toString());
    } catch (InterruptedException e) {
        log.error("could not chmod dir '" + dir.toString() + "' : " + e.getMessage());
        return false;
    } catch (IOException e) {
        log.error("could not chmod dir '" + dir.toString() + "' : " + e.getMessage());
        return false;
    }

    return true;
}

From source file:marytts.tools.voiceimport.HTKLabeler.java

private void htkExtraModels() throws Exception {

    String hlstats = getProp(HTKDIR) + File.separator + "HLStats";
    String hbuild = getProp(HTKDIR) + File.separator + "HBuild";

    File htkFile = new File(hlstats);
    if (!htkFile.exists()) {
        throw new RuntimeException("File " + htkFile.getAbsolutePath() + " does not exist");
    }/*from  w ww .  ja  v  a2s  . co  m*/
    String configFile = getProp(HTDIR) + File.separator + "config" + File.separator + "htkTrain.conf";
    String bigFile = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.phones.big";
    String phoneList = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.phone.list";
    String phoneMlf = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.phones.mlf";
    String phoneDict = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.phone.dict";
    String phoneAugDict = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.aug.phone.dict";
    String phoneAugList = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.aug.phone.list";

    String netFile = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.phones.net";

    Runtime rtime = Runtime.getRuntime();
    //get a shell
    Process process = rtime.exec("/bin/bash");
    //get an output stream to write to the shell
    PrintWriter pw = new PrintWriter(new OutputStreamWriter(process.getOutputStream()));
    System.out.println("( cd " + getProp(HTDIR) + "; " + hlstats + " -T 1 -C " + configFile + " -b " + bigFile
            + " -o " + phoneList + " " + phoneMlf + " > log_hlstats.txt" + "; exit )\n");

    pw.println("( cd " + getProp(HTDIR) + "; " + hlstats + " -T 1 -C " + configFile + " -b " + bigFile + " -o "
            + phoneList + " " + phoneMlf + " > log_hlstats.txt" + "; exit )\n");

    pw.flush();
    //shut down
    pw.close();
    process.waitFor();
    // check exit value
    if (process.exitValue() != 0) {
        BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
        throw new MaryConfigurationException(errorReader.readLine());
    }

    String fileDict = FileUtils.getFileAsString(new File(phoneDict), "ASCII");
    PrintWriter augPhoneDict = new PrintWriter(new FileWriter(phoneAugDict));
    augPhoneDict.println("!ENTER sil");
    augPhoneDict.print(fileDict);
    augPhoneDict.println("!EXIT sil");
    augPhoneDict.flush();
    augPhoneDict.close();

    String fileList = FileUtils.getFileAsString(new File(phoneList), "ASCII");
    PrintWriter augPhoneList = new PrintWriter(new FileWriter(phoneAugList));
    augPhoneList.println("!ENTER");
    augPhoneList.print(fileList);
    augPhoneList.println("!EXIT");
    augPhoneList.flush();
    augPhoneList.close();

    rtime = Runtime.getRuntime();
    //get a shell
    process = rtime.exec("/bin/bash");
    //get an output stream to write to the shell
    pw = new PrintWriter(new OutputStreamWriter(process.getOutputStream()));
    System.out.println("( cd " + getProp(HTDIR) + "; " + hbuild + " -T 1 -C " + configFile + " -n " + bigFile
            + " " + phoneAugList + " " + netFile + " > log_hbuild.txt" + "; exit )\n");

    pw.println("( cd " + getProp(HTDIR) + "; " + hbuild + " -T 1 -C " + configFile + " -n " + bigFile + " "
            + phoneAugList + " " + netFile + " > log_hbuild.txt" + "; exit )\n");

    pw.flush();
    //shut down
    pw.close();
    process.waitFor();
    // check exit value
    if (process.exitValue() != 0) {
        BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
        throw new MaryConfigurationException(errorReader.readLine());
    }

}

From source file:de.interactive_instruments.ShapeChange.Target.FeatureCatalogue.FeatureCatalogue.java

public void xsltWrite(File transformationSource, String xsltfileName, File transformationTarget) {

    try {/*from  w w  w .j  av  a  2s. com*/

        // ==============================
        // 1. perform additional checks
        // ==============================

        URI xsltMainFileUri = null;
        if (xsltPath.toLowerCase().startsWith("http")) {
            URL url = new URL(xsltPath + "/" + xsltfileName);
            xsltMainFileUri = url.toURI();
        } else {
            File xsl = new File(xsltPath + "/" + xsltfileName);
            if (xsl.exists()) {
                xsltMainFileUri = xsl.toURI();
            } else {
                result.addError(this, 18, xsl.getAbsolutePath());
                return;
            }
        }

        // ==============================
        // 2. perform the transformation
        // ==============================

        // determine if we need to run with a specific JRE
        if (pathToJavaExe == null) {

            // continue using current runtime environment
            XsltWriter writer = new XsltWriter(xslTransformerFactory, hrefMappings, transformationParameters,
                    result);

            writer.xsltWrite(transformationSource, xsltMainFileUri, transformationTarget);

        } else {

            // execute with JRE from configuration

            List<String> cmds = new ArrayList<String>();

            cmds.add(pathToJavaExe);

            if (javaOptions != null) {
                cmds.add(javaOptions);
            }

            cmds.add("-cp");
            List<String> cpEntries = new ArrayList<String>();

            // determine if execution from jar or from class file
            URL writerResource = XsltWriter.class.getResource("XsltWriter.class");
            String writerResourceAsString = writerResource.toString();

            if (writerResourceAsString.startsWith("jar:")) {

                // execution from jar

                // get path to main ShapeChange jar file
                String jarPath = writerResourceAsString.substring(4, writerResourceAsString.indexOf("!"));

                URI jarUri = new URI(jarPath);

                // add path to man jar file to class path entries
                File jarF = new File(jarUri);
                cpEntries.add(jarF.getPath());

                /*
                 * Get parent directory in which ShapeChange JAR file
                 * exists, because class path entries in manifest are
                 * defined relative to it.
                 */
                File jarDir = jarF.getParentFile();

                // get manifest and the classpath entries defined by it
                Manifest mf = new JarFile(jarF).getManifest();
                String classPath = mf.getMainAttributes().getValue("Class-Path");

                if (classPath != null) {

                    for (String dependency : classPath.split(" ")) {
                        // add path to dependency to class path entries
                        File dependencyF = new File(jarDir, dependency);
                        cpEntries.add(dependencyF.getPath());
                    }
                }

            } else {

                // execution with class files

                // get classpath entries from system class loader
                ClassLoader cl = ClassLoader.getSystemClassLoader();

                URL[] urls = ((URLClassLoader) cl).getURLs();

                for (URL url : urls) {
                    File dependencyF = new File(url.getPath());
                    cpEntries.add(dependencyF.getPath());
                }
            }

            String cpValue = StringUtils.join(cpEntries, System.getProperty("path.separator"));
            cmds.add("\"" + cpValue + "\"");

            /* add fully qualified name of XsltWriter class to command */
            cmds.add(XsltWriter.class.getName());

            // add parameter for hrefMappings (if defined)
            if (!hrefMappings.isEmpty()) {

                List<NameValuePair> hrefMappingsList = new ArrayList<NameValuePair>();
                for (Entry<String, URI> hrefM : hrefMappings.entrySet()) {
                    hrefMappingsList.add(new BasicNameValuePair(hrefM.getKey(), hrefM.getValue().toString()));
                }
                String hrefMappingsString = URLEncodedUtils.format(hrefMappingsList,
                        XsltWriter.ENCODING_CHARSET);

                /*
                 * NOTE: surrounding href mapping string with double quotes
                 * to avoid issues with using '=' inside the string when
                 * passed as parameter in invocation of java executable.
                 */
                cmds.add(XsltWriter.PARAM_hrefMappings);
                cmds.add("\"" + hrefMappingsString + "\"");
            }

            if (!transformationParameters.isEmpty()) {

                List<NameValuePair> transformationParametersList = new ArrayList<NameValuePair>();
                for (Entry<String, String> transParam : transformationParameters.entrySet()) {
                    transformationParametersList
                            .add(new BasicNameValuePair(transParam.getKey(), transParam.getValue()));
                }
                String transformationParametersString = URLEncodedUtils.format(transformationParametersList,
                        XsltWriter.ENCODING_CHARSET);

                /*
                 * NOTE: surrounding transformation parameter string with
                 * double quotes to avoid issues with using '=' inside the
                 * string when passed as parameter in invocation of java
                 * executable.
                 */
                cmds.add(XsltWriter.PARAM_transformationParameters);
                cmds.add("\"" + transformationParametersString + "\"");
            }

            if (xslTransformerFactory != null) {
                cmds.add(XsltWriter.PARAM_xslTransformerFactory);
                cmds.add(xslTransformerFactory);
            }

            String transformationSourcePath = transformationSource.getPath();
            String xsltMainFileUriString = xsltMainFileUri.toString();
            String transformationTargetPath = transformationTarget.getPath();

            cmds.add(XsltWriter.PARAM_transformationSourcePath);
            cmds.add("\"" + transformationSourcePath + "\"");

            cmds.add(XsltWriter.PARAM_transformationTargetPath);
            cmds.add("\"" + transformationTargetPath + "\"");

            cmds.add(XsltWriter.PARAM_xsltMainFileUri);
            cmds.add("\"" + xsltMainFileUriString + "\"");

            result.addInfo(this, 26, StringUtils.join(cmds, " "));

            ProcessBuilder pb = new ProcessBuilder(cmds);

            try {
                Process proc = pb.start();

                StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream());
                StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream());

                errorGobbler.start();
                outputGobbler.start();

                errorGobbler.join();
                outputGobbler.join();

                int exitVal = proc.waitFor();

                if (outputGobbler.hasResult()) {
                    result.addInfo(this, 25, outputGobbler.getResult());
                }

                if (exitVal != 0) {

                    // log error
                    if (errorGobbler.hasResult()) {
                        result.addError(this, 23, errorGobbler.getResult(), "" + exitVal);
                    } else {
                        result.addError(this, 24, "" + exitVal);
                    }
                }

            } catch (InterruptedException e) {
                result.addFatalError(this, 22);
                throw new ShapeChangeAbortException();
            }
        }

        // ==============
        // 2. log result
        // ==============

        if (OutputFormat.toLowerCase().contains("docx")) {

            // nothing to do here, the writeDOCX method adds the proper
            // result

        } else if (OutputFormat.toLowerCase().contains("framehtml")) {

            String outputDir = outputDirectory + "/" + outputFilename;

            result.addResult(getTargetID(), outputDir, "index.html", null);
        } else {
            result.addResult(getTargetID(), outputDirectory, transformationTarget.getName(), null);
        }

    } catch (Exception e) {
        String m = e.getMessage();
        if (m != null) {
            result.addError(m);
        }
        e.printStackTrace(System.err);
    }
}