Example usage for java.lang Process exitValue

List of usage examples for java.lang Process exitValue

Introduction

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

Prototype

public abstract int exitValue();

Source Link

Document

Returns the exit value for the process.

Usage

From source file:org.opencb.bionetdb.app.cli.CommandExecutor.java

@Deprecated
protected boolean runCommandLineProcess(File workingDirectory, String binPath, List<String> args,
        String logFilePath) throws IOException, InterruptedException {
    ProcessBuilder builder = getProcessBuilder(workingDirectory, binPath, args, logFilePath);

    logger.debug("Executing command: " + StringUtils.join(builder.command(), " "));
    Process process = builder.start();
    process.waitFor();/* ww w . java2  s  .c  om*/

    // Check process output
    boolean executedWithoutErrors = true;
    int genomeInfoExitValue = process.exitValue();
    if (genomeInfoExitValue != 0) {
        logger.warn("Error executing {}, error code: {}. More info in log file: {}", binPath,
                genomeInfoExitValue, logFilePath);
        executedWithoutErrors = false;
    }
    return executedWithoutErrors;
}

From source file:org.neo4j.vagrant.Shell.java

public Result run(String... cmds) {
    String cmd = StringUtils.join(cmds, " ");
    try {/*w  w  w.  j  a  va 2  s.c  o  m*/
        logOutput(shellName + " $ ", cmd);
        Process proc = startProcess(cmd);

        String msg = outputToString(shellName, proc.getInputStream())
                + outputToString(shellName, proc.getErrorStream());
        proc.waitFor();

        return new Result(proc.exitValue(), msg, cmd);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.sipfoundry.sipxconfig.admin.WebCertificateManagerImpl.java

public void copyKeyAndCertificate() {
    File sourceCertificate = getCRTFile();
    if (!sourceCertificate.exists()) {
        return;//from w  ww  . j ava2 s  . c om
    }

    File sourceKey = new File(m_certDirectory, getPrimaryServerFqdn() + "-web.key");
    if (!sourceKey.exists()) {
        return;
    }

    try {
        Runtime runtime = Runtime.getRuntime();
        String[] cmdLine = new String[] { m_binDirectory + GEN_SSL_KEYS_SH, WORKDIR_FLAG, m_certDirectory,
                "--pkcs", WEB_ONLY, DEFAULTS_FLAG, PARAMETERS_FLAG, PROPERTIES_FILE, };
        Process proc = runtime.exec(cmdLine);
        LOG.debug(RUNNING + StringUtils.join(cmdLine, BLANK));
        proc.waitFor();
        if (proc.exitValue() != 0) {
            throw new UserException(SCRIPT_ERROR, SCRIPT_EXCEPTION_MESSAGE + proc.exitValue());
        }
        File destinationCertificate = new File(m_sslDirectory, "ssl-web.crt");
        File destinationKey = new File(m_sslDirectory, "ssl-web.key");
        FileUtils.copyFile(sourceCertificate, destinationCertificate);
        FileUtils.copyFile(sourceKey, destinationKey);
        File sourceKeyStore = new File(m_certDirectory, getPrimaryServerFqdn() + "-web.keystore");
        File destinationKeyStore = new File(m_sslDirectory, "ssl-web.keystore");
        FileUtils.copyFile(sourceKeyStore, destinationKeyStore);
        File sourcePkcsKeyStore = new File(m_certDirectory, getPrimaryServerFqdn() + "-web.p12");
        File destinationPkcsKeyStore = new File(m_sslDirectory, "ssl-web.p12");
        FileUtils.copyFile(sourcePkcsKeyStore, destinationPkcsKeyStore);
    } catch (Exception e) {
        throw new UserException("&msg.copyError");
    }
}

From source file:org.eclipse.kura.deployment.customizer.upgrade.rp.UpgradeScriptResourceProcessorImpl.java

private void executeScript(File file) throws Exception {
    String path = file.getCanonicalPath();
    String[] cmdarray = { "/bin/bash", path };
    Runtime rt = Runtime.getRuntime();
    Process proc = null;
    try {/*from   w  ww.  ja  v a2 s  . c  o  m*/
        proc = rt.exec(cmdarray);
        if (proc.waitFor() != 0) {
            s_logger.error("Script {} failed with exit value {}", path, proc.exitValue());
        }
        // FIXME: streams must be consumed concurrently
    } catch (Exception e) {
        s_logger.error("Error executing process for script {}", path, e);
        throw e;
    } finally {
        if (proc != null) {
            proc.destroy();
        }
    }
}

From source file:net.solarnetwork.node.dao.jdbc.derby.DerbyOnlineSyncJob.java

private void performSync(String dbPath) {
    assert syncCommand != null;
    List<String> cmd = new ArrayList<String>(syncCommand.size());
    for (String param : syncCommand) {
        param = param.replace(SOURCE_DIRECTORY_PLACEHOLDER, dbPath);
        param = param.replace(DESTINATION_DIRECTORY_PLACEHOLDER, destinationPath);
        cmd.add(param);//from w w  w  . j  av  a2 s.c  o m
    }
    if (log.isDebugEnabled()) {
        StringBuilder buf = new StringBuilder();
        for (String p : cmd) {
            if (buf.length() > 0) {
                buf.append(' ');
            }
            buf.append(p);
        }
        log.debug("Derby sync command: {}", buf.toString());
    }
    ProcessBuilder pb = new ProcessBuilder(cmd);
    BufferedReader in = null;
    PrintWriter out = null;
    try {
        Process pr = pb.start();
        pr.waitFor();
        if (pr.exitValue() == 0) {
            if (log.isDebugEnabled()) {
                in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
                StringBuilder buf = new StringBuilder();
                String line = null;
                while ((line = in.readLine()) != null) {
                    buf.append(line).append('\n');
                }
                log.debug("Derby sync command output:\n{}", buf.toString());
            }
            log.info("Derby backup sync complete");
        } else {
            StringBuilder buf = new StringBuilder();
            in = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
            String line = null;
            while ((line = in.readLine()) != null) {
                buf.append(line).append('\n');
            }
            log.error("Sync command returned non-zero exit code {}: {}", pr.exitValue(), buf.toString().trim());
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                // ignore
            }
        }
        if (out != null) {
            out.flush();
            out.close();
        }
    }

}

From source file:com.netflix.dynomitemanager.defaultimpl.FloridaProcessManager.java

public void stop() throws IOException {
    logger.info("Stopping Dynomite server ....");
    List<String> command = Lists.newArrayList();
    if (!"root".equals(System.getProperty("user.name"))) {
        command.add(SUDO_STRING);/*from  w  w  w .  ja v a2  s . c  o  m*/
        command.add("-n");
        command.add("-E");
    }
    for (String param : config.getDynomiteStopScript().split(" ")) {
        if (StringUtils.isNotBlank(param))
            command.add(param);
    }
    ProcessBuilder stopCass = new ProcessBuilder(command);
    stopCass.directory(new File("/"));
    stopCass.redirectErrorStream(true);
    Process stopper = stopCass.start();

    sleeper.sleepQuietly(SCRIPT_EXECUTE_WAIT_TIME_MS);
    try {
        int code = stopper.exitValue();
        if (code == 0) {
            logger.info("Dynomite server has been stopped");
            instanceState.setStorageProxyAlive(false);
        } else {
            logger.error("Unable to stop Dynomite server. Error code: {}", code);
            logProcessOutput(stopper);
        }
    } catch (Exception e) {
        logger.warn("couldn't shut down Dynomite correctly", e);
    }
}

From source file:org.opencastproject.util.FileSupport.java

/**
 * Returns <code>true</code> if the operating system as well as the disk layout support creating a hard link from
 * <code>src</code> to <code>dest</code>. Note that this implementation requires two files rather than directories and
 * will overwrite any existing file that might already be present at the destination.
 * /*from w w  w  .  j ava  2s.c  o m*/
 * @param sourceLocation
 *          the source file
 * @param targetLocation
 *          the target file
 * @return <code>true</code> if the link was created, <code>false</code> otherwhise
 * @throws IOException
 *           if linking of the file failed
 */
public static boolean supportsLinking(File sourceLocation, File targetLocation) {
    if (sourceLocation == null)
        throw new IllegalArgumentException("Source location must not by null");
    if (targetLocation == null)
        throw new IllegalArgumentException("Target location must not by null");
    if (!sourceLocation.exists())
        throw new IllegalArgumentException("Source " + sourceLocation + " does not exist");

    logger.trace("Creating link from " + sourceLocation + " to " + targetLocation);
    Process p = null;
    StreamHelper stdout = null;
    StreamHelper stderr = null;
    StringBuffer error = new StringBuffer();
    try {
        p = createLinkFileProcess(sourceLocation, targetLocation, true);
        stdout = new StreamHelper(p.getInputStream());
        stderr = new LinkErrorStreamHelper(p.getErrorStream(), error);
        p.waitFor();
        stdout.stopReading();
        stderr.stopReading();
        // Find does not return with an error if -exec fails
        if (p.exitValue() != 0 || error.length() > 0) {
            logger.debug(
                    "Unable to create a link from " + sourceLocation + " to " + targetLocation + ": " + error);
            return false;
        }
        if (sourceLocation.length() != targetLocation.length()) {
            logger.warn("Source " + sourceLocation + " and target " + targetLocation
                    + " do not have the same length");
            // TOOD: Why would this happen?
            // throw new IOException("Source " + sourceLocation + " and target " +
            // dest + " do not have the same length");
        }
    } catch (Exception e) {
        logger.debug("Unable to create a link from " + sourceLocation + " to " + targetLocation + ": "
                + error.toString());
        return false;
    } finally {
        IoSupport.closeQuietly(stdout);
        IoSupport.closeQuietly(stderr);
        IoSupport.closeQuietly(p);
    }
    return true;
}

From source file:ms.safi.btsync.BTSyncApp.java

public boolean isAlive(Process p) {
    try {//from  ww  w  .j a v  a 2  s.  c  o  m
        p.exitValue();
        return false;
    } catch (IllegalThreadStateException e) {
        return true;
    }
}

From source file:com.palantir.docker.compose.execution.DockerComposeShould.java

private Process processWithOutput(String output) {
    Process mockedProcess = mock(Process.class);
    when(mockedProcess.getInputStream()).thenReturn(toInputStream(output));
    when(mockedProcess.exitValue()).thenReturn(0);
    return mockedProcess;
}

From source file:io.hops.hopsworks.api.zeppelin.util.ZeppelinResource.java

private void forceKillProccess(String pid) {
    String[] command = { "kill", "-9", pid };
    ProcessBuilder pb = new ProcessBuilder(command);
    if (pid == null) {
        return;//from w  ww  . ja  va 2  s  . c  om
    }
    try {
        Process p = pb.start();
        p.waitFor();
        p.exitValue();
    } catch (IOException | InterruptedException ex) {
        logger.log(Level.WARNING, "Problem killing Zeppelin Interpreter: {0}", ex.toString());
    }
}