Search in sources :

Example 1 with StreamExecReader

use of net.sf.latexdraw.util.StreamExecReader in project latexdraw by arnobl.

the class ViewText method execute.

/**
 * Executes a given command and returns the log.
 * @param cmd The command to execute.
 * @return True if the command exits normally plus the log.
 */
private Tuple<Boolean, String> execute(final String[] cmd) {
    String log = "";
    try {
        final Process process = Runtime.getRuntime().exec(cmd);
        final StreamExecReader errReader = new StreamExecReader(process.getErrorStream());
        final StreamExecReader outReader = new StreamExecReader(process.getInputStream());
        errReader.start();
        outReader.start();
        if (process.waitFor() == 0) {
            return new Tuple<>(true, log);
        }
        log = outReader.getLog() + LSystem.EOL + errReader.getLog();
    } catch (final IOException | InterruptedException | IllegalThreadStateException ex) {
        log += ex.getMessage();
    }
    return new Tuple<>(false, log);
}
Also used : StreamExecReader(net.sf.latexdraw.util.StreamExecReader) IOException(java.io.IOException) Tuple(net.sf.latexdraw.util.Tuple)

Aggregations

IOException (java.io.IOException)1 StreamExecReader (net.sf.latexdraw.util.StreamExecReader)1 Tuple (net.sf.latexdraw.util.Tuple)1