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);
}
Aggregations