List of usage examples for java.lang Process exitValue
public abstract int exitValue();
From source file:processing.app.CommandLineTest.java
@Test public void testCommandLineBuildWithRelativePath() throws Exception { Runtime rt = Runtime.getRuntime(); File wd = new File(buildPath, "build/shared/examples/01.Basics/Blink/"); Process pr = rt.exec(arduinoPath + " --board arduino:avr:uno --verify Blink.ino", null, wd); IOUtils.copy(pr.getInputStream(), System.out); pr.waitFor();//from w w w. j av a 2 s . co m assertEquals(0, pr.exitValue()); }
From source file:com.ikon.servlet.TextToSpeechServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String cmd = "espeak -v mb-es1 -f input.txt | mbrola -e /usr/share/mbrola/voices/es1 - -.wav " + "| oggenc -Q - -o output.ogg"; String text = WebUtils.getString(request, "text"); String docPath = WebUtils.getString(request, "docPath"); response.setContentType("audio/ogg"); FileInputStream fis = null;//from www . java 2 s . c om OutputStream os = null; try { if (!text.equals("")) { FileUtils.writeStringToFile(new File("input.txt"), text); } else if (!docPath.equals("")) { InputStream is = OKMDocument.getInstance().getContent(null, docPath, false); Document doc = OKMDocument.getInstance().getProperties(null, docPath); DocConverter.getInstance().doc2txt(is, doc.getMimeType(), new File("input.txt")); } // Convert to voice ProcessBuilder pb = new ProcessBuilder("/bin/sh", "-c", cmd); Process process = pb.start(); process.waitFor(); String info = IOUtils.toString(process.getInputStream()); process.destroy(); if (process.exitValue() == 1) { log.warn(info); } // Send to client os = response.getOutputStream(); fis = new FileInputStream("output.ogg"); IOUtils.copy(fis, os); os.flush(); } catch (InterruptedException e) { log.warn(e.getMessage(), e); } catch (IOException e) { log.warn(e.getMessage(), e); } catch (PathNotFoundException e) { log.warn(e.getMessage(), e); } catch (AccessDeniedException e) { log.warn(e.getMessage(), e); } catch (RepositoryException e) { log.warn(e.getMessage(), e); } catch (DatabaseException e) { log.warn(e.getMessage(), e); } catch (ConversionException e) { log.warn(e.getMessage(), e); } finally { IOUtils.closeQuietly(fis); IOUtils.closeQuietly(os); } }
From source file:org.gcaldaemon.core.file.CalendarReloader.java
private final void executeScript() throws Exception { // Execute script log.debug("Executing reloader script (" + cmd + ")..."); ProcessBuilder builder = new ProcessBuilder(args); Process script = builder.start(); sleep(1000L);/*from w ww .j a v a 2 s. co m*/ // Wait for script for (int i = 0; i < 15; i++) { try { script.exitValue(); } catch (Exception processNotExited) { sleep(1000L); } } // Destroy script script.destroy(); script = null; log.debug("Reloader script finished successfully."); }
From source file:com.samsung.sjs.ABackendTest.java
public void compilerTest(BiFunction<CompilerOptions, String[], Process> compiler, Function<String, Process> evaluator, boolean execute_code, boolean verbose, String... extra) { try {//ww w. j ava 2s.c om String script = getInputScriptPath(); System.out.println("Looking for test script: " + script); System.err.println("COMPILING: " + script); File scriptfile = new File(script); Path tmpdir = Files.createTempDirectory("__fawefwea8ew"); tmpdir.toFile().deleteOnExit(); String ccode = scriptfile.getName().replaceFirst(".js$", ".c"); File cfile = File.createTempFile("___", ccode, tmpdir.toFile()); String exec = ccode.replaceFirst(".c$", ""); File execfile = File.createTempFile("___", exec, tmpdir.toFile()); CompilerOptions opts = new CompilerOptions(CompilerOptions.Platform.Native, scriptfile.getAbsolutePath(), verbose, // -debugcompiler cfile.getAbsolutePath(), true /* use GC */, "clang", "emcc", execfile.getAbsolutePath(), baseDirectory(), false /* don't dump C compiler spew into JUnit console */, true /* apply field optimizations */, verbose /* emit type inference constraints to console */, verbose /* dump constraint solution to console */, null /* find runtime src for linking locally (not running from jar) */, shouldEncodeValues(), false /* TODO: x86Test passes explicit -m32 flag, rather than setting this */, false /* we don't care about error explanations */, null /* we don't care about error explanations */, false /* generate efl environment code */, 3 /* pass C compiler -O3 */); if (doInterop()) { opts.enableInteropMode(); } if (bootInterop()) { opts.startInInteropMode(); } Compiler.compile(opts); Process clang = compiler.apply(opts, extra); clang.waitFor(); if (clang.exitValue() != 0) { 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("!!!!!!!!!!!!! Compiler exited with value " + clang.exitValue()); System.err.println("Compiler stdout: " + compstdout); System.err.println("Compiler stderr: " + compstderr); } assertTrue(clang.exitValue() == 0); if (execute_code) { File prefixedscript = prefixJS(tmpdir, scriptfile); assertSameProcessOutput(runNode(prefixedscript), evaluator.apply(execfile.getAbsolutePath())); } } catch (Exception e) { e.printStackTrace(); assertTrue(false); } }
From source file:org.n52.wps.python.PythonScriptDelegator.java
private void executeScript(String command, File workspaceDir) //throws Exception { try {//w w w . j a v a2s. c o m Process p = Runtime.getRuntime().exec(command, null, workspaceDir); p.waitFor(); if (p.exitValue() == 0) { LOGGER.info("Successfull termination of command:\n" + command); } else { LOGGER.error("Abnormal termination of command:\n" + command); LOGGER.error("Errorlevel / Exit Value: " + p.exitValue()); throw new IOException(); } } catch (IOException e) { LOGGER.error("Error executing command:\n" + command); e.printStackTrace(); //throw new Exception(); } catch (InterruptedException e) { LOGGER.error("Execution interrupted! Command was:\n" + command); e.printStackTrace(); //throw new Exception(); } }
From source file:org.opencb.cellbase.app.cli.CommandExecutor.java
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();/* w w w.j a v a 2 s . c o m*/ // 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.sipfoundry.sipxconfig.admin.WebCertificateManagerImpl.java
public void generateCSRFile() { try {//from ww w .j a va 2 s .c o m Runtime runtime = Runtime.getRuntime(); String[] cmdLine = new String[] { m_binDirectory + GEN_SSL_KEYS_SH, "--csr", WEB_ONLY, DEFAULTS_FLAG, PARAMETERS_FLAG, PROPERTIES_FILE, WORKDIR_FLAG, m_certDirectory }; Process proc = runtime.exec(cmdLine); LOG.debug("Executing: " + StringUtils.join(cmdLine, BLANK)); proc.waitFor(); if (proc.exitValue() != 0) { throw new UserException(SCRIPT_ERROR, SCRIPT_EXCEPTION_MESSAGE + proc.exitValue()); } } catch (IOException e) { throw new UserException(SCRIPT_ERROR, e.getMessage()); } catch (InterruptedException e) { throw new UserException(SCRIPT_ERROR, e.getMessage()); } }
From source file:com.thoughtworks.go.server.database.Migrate.java
private int exec(String[] command) { try {/*ww w .j a v a 2s . c om*/ if (LOGGER.isDebugEnabled()) { LOGGER.debug("About to execute commands:"); for (String c : command) { LOGGER.debug(c); } } Process p = Runtime.getRuntime().exec(command); copyInThread(p.getInputStream(), quiet ? null : sysOut); copyInThread(p.getErrorStream(), quiet ? null : sysOut); p.waitFor(); return p.exitValue(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.netflix.raigad.defaultimpl.ElasticSearchProcessManager.java
public void start(boolean join_ring) throws IOException { logger.info("Starting elasticsearch server"); List<String> command = Lists.newArrayList(); if (!"root".equals(System.getProperty("user.name"))) { command.add(SUDO_STRING);//from w w w . j av a2 s .c o m command.add("-n"); command.add("-E"); } command.addAll(getStartCommand()); ProcessBuilder startEs = new ProcessBuilder(command); Map<String, String> env = startEs.environment(); env.put("DATA_DIR", config.getDataFileLocation()); startEs.directory(new File("/")); startEs.redirectErrorStream(true); Process starter = startEs.start(); logger.info("Starting Elasticsearch server ...."); try { sleeper.sleepQuietly(SCRIPT_EXECUTE_WAIT_TIME_MS); int code = starter.exitValue(); if (code == 0) logger.info("Elasticsearch server has been started"); else logger.error("Unable to start Elasticsearch server. Error code: {}", code); logProcessOutput(starter); } catch (Exception e) { logger.warn("Starting Elasticsearch has an error", e.getMessage()); } }
From source file:org.redhat.jboss.maven.plugins.JBossProfileGeneratorMojo.java
public boolean executeCmd(String command) { try {/*from w ww . j a v a 2 s .c o m*/ Process process = Runtime.getRuntime().exec(command); process.waitFor(); IOUtils.copy(process.getInputStream(), System.out); return process.exitValue() == 0 ? true : false; } catch (Exception e) { getLog().error(e.getMessage()); return false; } }