List of usage examples for java.lang Process exitValue
public abstract int exitValue();
From source file:io.syndesis.verifier.LocalProcessVerifier.java
private Properties runValidator(String classpath, Verifier.Scope scope, String camelPrefix, Properties request) throws IOException, InterruptedException { Process java = new ProcessBuilder().command("java", "-classpath", classpath, "io.syndesis.connector.ConnectorVerifier", scope.toString(), camelPrefix) .redirectError(ProcessBuilder.Redirect.INHERIT).start(); try (OutputStream os = java.getOutputStream()) { request.store(os, null);/*from ww w . ja va 2 s. c om*/ } Properties result = new Properties(); try (InputStream is = java.getInputStream()) { result.load(is); } if (java.waitFor() != 0) { throw new IOException("Verifier failed with exit code: " + java.exitValue()); } return result; }
From source file:org.sipfoundry.sipxconfig.admin.CertificateManagerImpl.java
public void importKeyAndCertificate(String server, boolean isCsrBased) { File newCertificate = isCsrBased ? getCRTFile(server) : getExternalCRTFile(); if (!newCertificate.exists()) { throw new UserException(ERROR_VALID); }/*from w w w .j a v a2s. c om*/ File newKey = isCsrBased ? getKeyFile(server) : getExternalKeyFile(); if (!newKey.exists()) { throw new UserException(ERROR_VALID); } if (!validateCertificate(newCertificate)) { throw new UserException(ERROR_VALID); } File oldCertificate = new File(m_sslDirectory, "ssl-web.crt"); File oldKey = new File(m_sslDirectory, "ssl-web.key"); File backupCertificate = new File(m_sslDirectory, "ssl-web.oldcrt"); File backupKey = new File(m_sslDirectory, "ssl-web.oldkey"); try { if (isCsrBased) { Runtime runtime = Runtime.getRuntime(); String[] cmdLine = new String[] { m_binCertDirectory + 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()); } } FileUtils.copyFile(oldCertificate, backupCertificate); FileUtils.copyFile(oldKey, backupKey); FileUtils.copyFile(newCertificate, oldCertificate); FileUtils.copyFile(newKey, oldKey); } catch (Exception ex) { throw new UserException(ERROR_MSG_COPY); } try { generateKeyStores(); } catch (UserException userException) { try { FileUtils.copyFile(backupCertificate, oldCertificate); FileUtils.copyFile(backupKey, oldKey); backupCertificate.delete(); backupKey.delete(); } catch (Exception ex) { throw new UserException(ERROR_MSG_COPY); } throw userException; } backupCertificate.delete(); backupKey.delete(); }
From source file:org.codesearch.commons.plugins.vcs.HgLocalPlugin.java
private byte[] executeHgCommand(String... arguments) throws VersionControlPluginException { try {/* w w w .j av a2 s .com*/ List<String> command = new LinkedList<String>(); command.add(HG_BINARY_LOCATION); command.add(HG_DEFAULT_ARGUMENTS); command.addAll(Arrays.asList(arguments)); Process process = null; synchronized (this) { processBuilder = new ProcessBuilder(); processBuilder.directory(branchDirectory); processBuilder.command(command); LOG.trace("Executing hg command: " + processBuilder.command()); process = processBuilder.start(); byte[] output = IOUtils.toByteArray(process.getInputStream()); process.waitFor(); if (process.exitValue() != 0) { throw new VersionControlPluginException("Hg returned error code: " + process.exitValue() + "\n Output: " + IOUtils.toString(process.getErrorStream())); } cleanupProcess(process); return output; } } catch (InterruptedException ex) { throw new VersionControlPluginException("Execution of hg interrupted by operating system"); } catch (IOException ex) { throw new VersionControlPluginException("Error executing hg command: " + ex); } }
From source file:org.scantegrity.scanner.ScannerController.java
/** * Full Constructor. Most of the common options can be set. * /* w w w . j a v a 2 s .c om*/ * @param p_log - The logging option. * @param p_binpath - The path to the binaries for the scannercontroller. * @param p_inpath - The path for input (image files). This should be a ramdisk! * @param p_outpath - Where output files should be stored. * @throws IOException * @throws InterruptedException */ public ScannerController(Logging p_log, String p_binpath, String p_inpath, String p_outpath, boolean p_delete) { if (p_binpath != null) c_binpath = p_binpath; if (p_outpath != null) setOutpath(p_outpath); if (p_inpath != null) setInpath(p_inpath); c_delete = p_delete; c_log = p_log; if (c_log == null) { Vector<String> l_out = new Vector<String>(); l_out.add(""); c_log = new Logging(l_out, -1, Level.OFF); } //Can I read/write to the paths? //....Assume we can read/write to "" try { File l_f = new File(p_binpath); if (!l_f.exists() || !l_f.isDirectory() || !l_f.canRead()) { p_binpath = ""; } } catch (Exception l_e) { p_binpath = ""; } if (p_binpath == "") { c_log.log(Level.WARNING, "Binary path is unusable: " + p_binpath); } //input path try { File l_f = new File(p_inpath); if (!l_f.exists() || !l_f.isDirectory() || !l_f.canRead()) { p_inpath = ""; } } catch (Exception l_e) { p_inpath = ""; } if (p_inpath == "") { c_log.log(Level.WARNING, "In path is unusable: " + p_inpath); } //output path try { File l_f = new File(p_outpath); if (!l_f.exists() || !l_f.isDirectory() || !l_f.canWrite()) { p_outpath = ""; } } catch (Exception l_e) { p_outpath = ""; } if (p_outpath == "") { c_log.log(Level.WARNING, "Output path is unusable: " + p_outpath); } try { //Test to make sure the command works. Process l_p = Runtime.getRuntime().exec(c_binpath + c_scanimgcmd + " " + c_testopts); synchronized (this) { l_p.waitFor(); if (l_p.exitValue() != 0) { String l_err = "Unable to open scanning program. Error: "; l_err += getErrorMsg(l_p); c_log.log(Level.SEVERE, l_err); } else { c_log.log(Level.INFO, "Scanner control initialized and working."); } closeProcess(l_p); } } catch (Exception l_e) { c_log.log(Level.SEVERE, "Unable to start scanning program!" + l_e.getMessage()); } }
From source file:org.structr.web.test.FrontendTest.java
protected int run(final String testName) { try (final Tx tx = app.tx()) { createAdminUser();//from ww w . j a v a 2s . c om createResourceAccess("_login", UiAuthenticator.NON_AUTH_USER_POST); tx.success(); } catch (Exception ex) { logger.log(Level.SEVERE, null, ex); } try (final Tx tx = app.tx()) { String[] args = { "/bin/sh", "-c", "cd src/test/javascript ; PATH=./bin/`uname`/:$PATH casperjs/bin/casperjs --httpPort=" + httpPort + " test " + testName + ".js" }; Process proc = Runtime.getRuntime().exec(args); logger.log(Level.INFO, IOUtils.toString(proc.getInputStream())); String warnings = IOUtils.toString(proc.getErrorStream()); if (StringUtils.isNotBlank(warnings)) { logger.log(Level.WARNING, warnings); } final int maxRetries = 60; Integer exitValue = 1; // default is error try { int r = 0; while (proc.isAlive() && r < maxRetries) { Thread.sleep(1000); r++; } exitValue = proc.exitValue(); makeVideo(testName); return exitValue; } catch (IllegalThreadStateException ex) { logger.log(Level.WARNING, "Subprocess has not properly exited", ex); ex.printStackTrace(); } logger.log(Level.INFO, "casperjs subprocess returned with {0}", exitValue); tx.success(); } catch (Exception ex) { logger.log(Level.SEVERE, null, ex); } return 1; }
From source file:com.adito.boot.Util.java
/** * Attempt to make a file executable. Only current works on * systems that have the <b>chmod</b> command available. * //from ww w . ja v a2s . co m * @param binLocation * @throws IOException on any error */ public static void makeExecutable(File binLocation) throws IOException { Process p = Runtime.getRuntime().exec(new String[] { "chmod", "ug+rx", binLocation.getAbsolutePath() }); try { copy(p.getErrorStream(), new ByteArrayOutputStream()); } finally { try { if (p.waitFor() != 0) { throw new IOException("Failed to set execute permission. Return code " + p.exitValue() + "."); } } catch (InterruptedException e) { } } }
From source file:org.sonatype.flexmojos.tests.AbstractFlexMojosTests.java
protected void assertSeftExit(File main, int expectedExitCode) throws Exception { Process p = null; try {// w w w .j a v a2 s .c o m p = Runtime.getRuntime().exec(new String[] { "flashplayer", main.getCanonicalPath() }); final Process tp = p; Thread t = new Thread(new Runnable() { public void run() { try { tp.waitFor(); } catch (InterruptedException e) { } } }); t.start(); t.join(10000); MatcherAssert.assertThat(p.exitValue(), CoreMatchers.equalTo(expectedExitCode)); } finally { if (p != null) p.destroy(); } }
From source file:org.structr.web.basic.FrontendTest.java
protected int run(final String testName) { try (final Tx tx = app.tx()) { createAdminUser();//ww w . jav a2 s . c om createResourceAccess("_login", UiAuthenticator.NON_AUTH_USER_POST); tx.success(); } catch (Exception ex) { logger.error("", ex); } try (final Tx tx = app.tx()) { String[] args = { "/bin/sh", "-c", "cd src/test/javascript ; PATH=./bin/`uname`/:$PATH casperjs/bin/casperjs --httpPort=" + httpPort + " test " + testName + ".js" }; Process proc = Runtime.getRuntime().exec(args); logger.info(IOUtils.toString(proc.getInputStream())); String warnings = IOUtils.toString(proc.getErrorStream()); if (StringUtils.isNotBlank(warnings)) { logger.warn(warnings); } final int maxRetries = 60; Integer exitValue = 1; // default is error try { int r = 0; while (proc.isAlive() && r < maxRetries) { Thread.sleep(1000); r++; } exitValue = proc.exitValue(); makeVideo(testName); return exitValue; } catch (IllegalThreadStateException ex) { logger.warn("Subprocess has not properly exited", ex); logger.warn("", ex); } logger.info("casperjs subprocess returned with {}", exitValue); tx.success(); } catch (Exception ex) { logger.error("", ex); } return 1; }
From source file:uk.co.codezen.maven.composer.mojo.AbstractComposerMojo.java
/** * Execute an arbitrary command, forwarding the process stdout to the Log info level * and the process stderr to the Java error level. * * @param command Command to execute//from w w w . j av a2s . c om * @param workingDirectory Working directory * @throws IOException IO problem executing command */ private int runCommand(List<String> command, String workingDirectory) throws IOException { ProcessBuilder processBuilder = new ProcessBuilder(command); processBuilder.directory(new File(workingDirectory)); Process composerProcess = processBuilder.start(); // Link Maven stdout/stderr with process pipe(composerProcess.getInputStream(), System.out); pipe(composerProcess.getErrorStream(), System.err); while (true) { try { composerProcess.waitFor(); break; } catch (InterruptedException e) { // Do nothing, re-run loop } } return composerProcess.exitValue(); }
From source file:com.wakatime.intellij.plugin.WakaTime.java
private static void sendHeartbeat(final Heartbeat heartbeat, final ArrayList<Heartbeat> extraHeartbeats) { final String[] cmds = buildCliCommand(heartbeat, extraHeartbeats); log.debug("Executing CLI: " + Arrays.toString(obfuscateKey(cmds))); try {//from w w w . j a v a 2 s . c o m Process proc = Runtime.getRuntime().exec(cmds); if (extraHeartbeats.size() > 0) { String json = toJSON(extraHeartbeats); log.debug(json); try { BufferedWriter stdin = new BufferedWriter(new OutputStreamWriter(proc.getOutputStream())); stdin.write(json); stdin.write("\n"); try { stdin.flush(); stdin.close(); } catch (IOException e) { /* ignored because wakatime-cli closes pipe after receiving \n */ } } catch (IOException e) { log.warn(e); } } if (WakaTime.DEBUG) { BufferedReader stdout = new BufferedReader(new InputStreamReader(proc.getInputStream())); BufferedReader stderr = new BufferedReader(new InputStreamReader(proc.getErrorStream())); proc.waitFor(); String s; while ((s = stdout.readLine()) != null) { log.debug(s); } while ((s = stderr.readLine()) != null) { log.debug(s); } log.debug("Command finished with return value: " + proc.exitValue()); } } catch (Exception e) { log.warn(e); } }