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:com.twosigma.beaker.core.rest.PluginServiceLocatorRest.java

private static void startGobblers(Process proc, String name, OutputLogService outputLogService,
        String waitfor) {//from   ww  w  . ja v  a  2s.c om
    StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "stderr", name, outputLogService,
            waitfor);
    errorGobbler.start();

    StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "stdout", name, outputLogService);
    outputGobbler.start();
}

From source file:com.synflow.cx.tests.codegen.CodegenPassTests.java

/**
 * Executes a command in the path given by the location, and returns its exit code.
 * //from  ww  w . j a  v  a  2s . c  o m
 * @param directory
 *            a directory
 * @param command
 *            a list of String
 * @return the return code of the process
 * @throws IOException
 * @throws InterruptedException
 */
protected final Process executeCommand(File directory, String... command)
        throws IOException, InterruptedException {
    ProcessBuilder pb = new ProcessBuilder(command).directory(directory);
    Process process = pb.start();
    new StreamCopier(process.getErrorStream(), System.err).start();
    return process;
}

From source file:edu.ucsd.sbrg.escher.EscherConverter.java

/**
 * Extracts CoBRA from {@link SBMLDocument} if it is FBC compliant. cobrapy must be present for
 * this./*from w ww. j a v a 2s .c o  m*/
 *
 * @param file Input file.
 * @return Result of extraction.
 * @throws IOException Thrown if there are problems in reading the {@code input} file(s).
 * @throws XMLStreamException Thrown if there are problems in parsing XML file(s).
 */
public static boolean extractCobraModel(File file) throws IOException, XMLStreamException {
    if (false) {
        logger.warning(format(bundle.getString("SBMLFBCNotAvailable"), file.getName()));
        return false;
    } else {
        logger.info(format(bundle.getString("SBMLFBCInit"), file.getName()));
        // Execute: py3 -c "from cobra import io;
        // io.save_json_model(model=io.read_sbml_model('FILENAME'), file_name='FILENAME')"

        String[] command;
        command = new String[] { "python3", "-c",
                "\"print('yo');from cobra import io;" + "io.save_json_model(model=io.read_sbml_model('"
                        + file.getAbsolutePath() + "'), file_name='" + file.getAbsolutePath() + ".json"
                        + "');print('yo')\"",
                "> /temp/log" };
        // command = new String[] {"/usr/local/bin/python3", "-c", "\"print('yo')\""};
        command = new String[] { "python3" };
        Process p;
        try {
            // p = new ProcessBuilder(command).redirectErrorStream(true).start();
            p = Runtime.getRuntime().exec(command);
            p.waitFor();
            if (p.exitValue() == 0) {
                logger.info(format(bundle.getString("SBMLFBCExtractionSuccessful"), file.getAbsolutePath(),
                        file.getAbsolutePath()));
                InputStream is = p.getErrorStream();
                is = p.getInputStream();
                OutputStream os = p.getOutputStream();
                BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
                String cobrapy_output = "";
                cobrapy_output = reader.readLine();
                while (cobrapy_output != null) {
                    logger.warning(cobrapy_output);
                    cobrapy_output = reader.readLine();
                }
                return true;
            } else {
                logger.info(format(bundle.getString("SBMLFBCExtractionFailed")));
                BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
                String cobrapy_output = "";
                cobrapy_output = reader.readLine();
                while (cobrapy_output != null) {
                    logger.warning(cobrapy_output);
                    cobrapy_output = reader.readLine();
                }
                return false;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
            return false;
        }
    }
}

From source file:Main.java

public static int doShellCommand(String[] cmds, StringBuilder log, boolean runAsRoot, boolean waitFor)
        throws Exception {

    Process proc = null;
    int exitCode = -1;

    if (runAsRoot) {
        proc = Runtime.getRuntime().exec("su");
    } else {//from w w w. j a  va2 s .  com
        proc = Runtime.getRuntime().exec("sh");
    }

    OutputStreamWriter out = new OutputStreamWriter(proc.getOutputStream());

    for (int i = 0; i < cmds.length; i++) {
        // TorService.logMessage("executing shell cmd: " + cmds[i] +
        // "; runAsRoot=" + runAsRoot + ";waitFor=" + waitFor);

        out.write(cmds[i]);
        out.write("\n");
    }

    out.flush();
    out.write("exit\n");
    out.flush();

    if (waitFor) {

        final char buf[] = new char[10];

        // Consume the "stdout"
        InputStreamReader reader = new InputStreamReader(proc.getInputStream());
        int read = 0;
        while ((read = reader.read(buf)) != -1) {
            if (log != null) {
                log.append(buf, 0, read);
            }
        }

        // Consume the "stderr"
        reader = new InputStreamReader(proc.getErrorStream());
        read = 0;
        while ((read = reader.read(buf)) != -1) {
            if (log != null) {
                log.append(buf, 0, read);
            }
        }

        exitCode = proc.waitFor();

    }

    return exitCode;

}

From source file:controllerTas.actions.gnuplot.GnuplotExec.java

protected void checkForError(Process p) throws IOException, GnuplotException {
    BufferedReader stderr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    String read;//  w  ww  . j  a v  a2  s. c  om

    StringBuilder errorString = new StringBuilder();
    boolean error = false;

    while ((read = stderr.readLine()) != null) {
        errorString.append(read);
        error = true;
    }

    if (error) {
        log.warn(errorString.toString());
        throw new GnuplotException((read));
    }
}

From source file:Main.java

public static int doShellCommand(String[] cmds, StringBuilder log, boolean runAsRoot, boolean waitFor)
        throws Exception {

    Process proc = null;
    int exitCode = -1;

    if (runAsRoot)
        proc = Runtime.getRuntime().exec("su");
    else//from www  .j a  v a 2  s.  c om
        proc = Runtime.getRuntime().exec("sh");

    OutputStreamWriter out = new OutputStreamWriter(proc.getOutputStream());

    for (int i = 0; i < cmds.length; i++) {
        Log.d("the-onion-phone",
                "executing shell cmd: " + cmds[i] + "; runAsRoot=" + runAsRoot + ";waitFor=" + waitFor);

        out.write(cmds[i]);
        out.write("\n");
    }

    out.flush();
    out.write("exit\n");
    out.flush();

    if (waitFor) {

        final char buf[] = new char[10];

        // Consume the "stdout"
        InputStreamReader reader = new InputStreamReader(proc.getInputStream());
        int read = 0;
        while ((read = reader.read(buf)) != -1) {
            if (log != null)
                log.append(buf, 0, read);
        }

        // Consume the "stderr"
        reader = new InputStreamReader(proc.getErrorStream());
        read = 0;
        while ((read = reader.read(buf)) != -1) {
            if (log != null)
                log.append(buf, 0, read);
        }

        exitCode = proc.waitFor();

    }

    return exitCode;

}

From source file:configuration.Cluster.java

public static String[] call_Python_Process(String script, String commands)
        throws IOException, InterruptedException {
    //System.out.println("Commands>"+commands);
    String STDoutput = "";
    String STDError = "";

    Process p = Runtime.getRuntime().exec("python " + script + " " + commands);
    BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    String line = "";

    // Check Output
    while ((line = bri.readLine()) != null) {
        STDoutput += line;//www  . j  a  v  a 2s.co  m
    }
    bri.close();
    while ((line = bre.readLine()) != null) {
        STDError += line;
    }
    bre.close();
    p.waitFor();

    String[] tab = { STDoutput, STDError };
    return tab;
}

From source file:com.samsung.sjs.Compiler.java

public static int manage_c_compiler(Process clang, CompilerOptions opts)
        throws IOException, InterruptedException {
    clang.waitFor();/*  w  w  w  .ja  va2 s  . c  om*/
    if (clang.exitValue() != 0 && !opts.debug()) {
        // If clang failed and we didn't already dump its stderr
        StringWriter w_stdout = new StringWriter(), w_stderr = new StringWriter();
        IOUtils.copy(clang.getInputStream(), w_stdout, Charset.defaultCharset());
        IOUtils.copy(clang.getErrorStream(), w_stderr, Charset.defaultCharset());
        String compstdout = w_stdout.toString();
        String compstderr = w_stderr.toString();
        System.err.println("C compiler [" + opts.clangPath() + "] failed.");
        System.out.println("C compiler stdout:");
        System.out.println(compstdout);
        System.err.println("C compiler stderr:");
        System.err.println(compstderr);
    }
    return clang.exitValue();
}

From source file:LogOutput.java

public void logOutput(BuildListener listener, Process process) throws IOException {

    if (process != null) {
        String output = IOUtils.toString(process.getInputStream());
        String errorOutput = IOUtils.toString(process.getErrorStream());

        logToJvm(output, errorOutput);/*from w ww  . j a  v a2  s  .  c  om*/

        logToConsole(listener, output, errorOutput);
    }

}

From source file:ezbake.deployer.publishers.local.BaseLocalPublisher.java

protected void dumpIO(Process process) {
    inheritIO(process.getInputStream(), System.out);
    inheritIO(process.getErrorStream(), System.err);
}