List of usage examples for java.lang ProcessBuilder start
public Process start() throws IOException
From source file:com.googlecode.jmxtrans.model.output.RRDToolWriter.java
/** * Executes the rrdtool update command./*from w w w. j av a 2 s. com*/ */ protected void rrdToolUpdate(String template, String data) throws Exception { List<String> commands = new ArrayList<>(); commands.add(binaryPath + "/rrdtool"); commands.add("update"); commands.add(outputFile.getCanonicalPath()); commands.add("-t"); commands.add(template); commands.add("N:" + data); ProcessBuilder pb = new ProcessBuilder(commands); Process process = pb.start(); checkErrorStream(process); }
From source file:zipkin.execjar.ExecJarRule.java
@Override public Statement apply(Statement base, Description description) { return new Statement() { public void evaluate() throws Throwable { try { ProcessBuilder bootBuilder = new ProcessBuilder("java", "-jar", execJar); bootBuilder.environment().put("SERVER_PORT", String.valueOf(port())); bootBuilder.environment().putAll(environment); bootBuilder.redirectErrorStream(true); bootApp = bootBuilder.start(); CountDownLatch startedOrCrashed = new CountDownLatch(1); Thread consoleReader = new Thread(() -> { boolean foundStartMessage = false; try (BufferedReader reader = new BufferedReader( new InputStreamReader(bootApp.getInputStream()))) { String line; while ((line = reader.readLine()) != null) { if (line.indexOf("JVM running for") != -1) { foundStartMessage = true; startedOrCrashed.countDown(); }/*from w w w . j av a 2 s .com*/ console.add(line); } } catch (Exception e) { } finally { if (!foundStartMessage) startedOrCrashed.countDown(); } }); consoleReader.setDaemon(true); consoleReader.start(); if (!startedOrCrashed.await(10, TimeUnit.SECONDS)) { throw new AssumptionViolatedException("Took too long to start or crash"); } base.evaluate(); } finally { bootApp.destroy(); } } }; }
From source file:hydrograph.ui.graph.execution.tracking.utils.TrackingDisplayUtils.java
/** * This function will be return process ID which running on defined port. * // ww w . ja va2s . co m * @return the service port pid * @throws IOException * Signals that an I/O exception has occurred. */ public String getServicePortPID(Properties properties) throws IOException { int portNumber = Integer.parseInt(properties.getProperty(EXECUTION_TRACKING_PORT)); if (OSValidator.isWindows()) { ProcessBuilder builder = new ProcessBuilder( new String[] { "cmd", "/c", "netstat -a -o -n |findstr :" + portNumber }); Process process = builder.start(); InputStream inputStream = process.getInputStream(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); String str = bufferedReader.readLine(); str = StringUtils.substringAfter(str, "LISTENING"); str = StringUtils.trim(str); return str; } return ""; }
From source file:io.hops.hopsworks.common.dao.tensorflow.config.TensorBoardProcessMgr.java
/** * Check to see if the process is running and is a TensorBoard started by tensorboard.sh * @param pid/*from w ww . j a va2s. c om*/ * @return */ @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public int ping(BigInteger pid) { String prog = settings.getHopsworksDomainDir() + "/bin/tensorboard.sh"; int exitValue = 1; String[] command = { "/usr/bin/sudo", prog, "ping", pid.toString() }; LOGGER.log(Level.INFO, Arrays.toString(command)); ProcessBuilder pb = new ProcessBuilder(command); try { Process process = pb.start(); process.waitFor(20l, TimeUnit.SECONDS); exitValue = process.exitValue(); } catch (IOException | InterruptedException ex) { LOGGER.log(Level.SEVERE, "Problem pinging: {0}", ex.toString()); } return exitValue; }
From source file:io.hops.hopsworks.common.dao.tensorflow.config.TensorBoardProcessMgr.java
/** * Kill the TensorBoard process// w w w . j a v a 2 s. com * @param pid * @return */ @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public int killTensorBoard(BigInteger pid) { String prog = settings.getHopsworksDomainDir() + "/bin/tensorboard.sh"; int exitValue; String[] command = { "/usr/bin/sudo", prog, "kill", pid.toString() }; LOGGER.log(Level.INFO, Arrays.toString(command)); ProcessBuilder pb = new ProcessBuilder(command); try { Process process = pb.start(); process.waitFor(20l, TimeUnit.SECONDS); exitValue = process.exitValue(); } catch (IOException | InterruptedException ex) { exitValue = 2; LOGGER.log(Level.SEVERE, "Failed to kill TensorBoard", ex); } return exitValue; }
From source file:io.hops.hopsworks.common.dao.tensorflow.config.TensorBoardProcessMgr.java
/** * Kill the TensorBoard process/*from w ww.ja v a2 s . c o m*/ * @param tb * @return */ @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public int killTensorBoard(TensorBoard tb) throws ServiceException { String prog = settings.getHopsworksDomainDir() + "/bin/tensorboard.sh"; int exitValue; String[] command = { "/usr/bin/sudo", prog, "kill", tb.getPid().toString() }; LOGGER.log(Level.INFO, Arrays.toString(command)); ProcessBuilder pb = new ProcessBuilder(command); try { Process process = pb.start(); process.waitFor(20l, TimeUnit.SECONDS); exitValue = process.exitValue(); cleanupLocalTBDir(tb); } catch (IOException | InterruptedException ex) { exitValue = 2; LOGGER.log(Level.SEVERE, "Failed to kill TensorBoard", ex); } return exitValue; }
From source file:com.googlecode.jmxtrans.model.output.RRDToolWriter.java
/** * Calls out to the rrdtool binary with the 'create' command. *//*from ww w . j ava2s . c o m*/ protected void rrdToolCreateDatabase(RrdDef def) throws Exception { List<String> commands = new ArrayList<>(); commands.add(this.binaryPath + "/rrdtool"); commands.add("create"); commands.add(this.outputFile.getCanonicalPath()); commands.add("-s"); commands.add(String.valueOf(def.getStep())); for (DsDef dsdef : def.getDsDefs()) { commands.add(getDsDefStr(dsdef)); } for (ArcDef adef : def.getArcDefs()) { commands.add(getRraStr(adef)); } ProcessBuilder pb = new ProcessBuilder(commands); Process process = pb.start(); try { checkErrorStream(process); } finally { IOUtils.closeQuietly(process.getInputStream()); IOUtils.closeQuietly(process.getOutputStream()); IOUtils.closeQuietly(process.getErrorStream()); } }
From source file:net.urlgrey.mythpodcaster.transcode.SegmentedVodTranscoderImpl.java
public void transcode(File workingDirectory, GenericTranscoderConfigurationItem genericConfig, File inputFile, File outputFile) throws Exception { LOG.info("transcode started: inputFile [" + inputFile.getAbsolutePath() + "], outputFile [" + outputFile.getAbsolutePath() + "]"); SegmenterTranscoderConfigurationItem config = (SegmenterTranscoderConfigurationItem) genericConfig; List<String> commandList = new ArrayList<String>(); commandList.add(niceLocation);//from w w w. jav a 2 s . c o m commandList.add("-n"); commandList.add(Integer.toString(config.getNiceness())); commandList.add(segmenterLocation); commandList.add(inputFile.getAbsolutePath()); commandList.add(config.getSegmentDuration()); commandList.add(config.getSegmentFilePrefix()); commandList.add(config.getPlaylistFileName()); commandList.add(config.getHttpPrefix()); ProcessBuilder pb = new ProcessBuilder(commandList); pb.environment().put("LD_LIBRARY_PATH", "/usr/local/lib:"); pb.redirectErrorStream(true); pb.directory(outputFile.getParentFile()); Process process = null; try { // Get the segmenter process process = pb.start(); // We give a couple of secs to complete task if needed Future<List<String>> stdout = pool.submit(new OutputMonitor(process.getInputStream())); List<String> result = stdout.get(config.getTimeout(), TimeUnit.SECONDS); process.waitFor(); final int exitValue = process.exitValue(); LOG.info("Segmenter exit value: " + exitValue); if (exitValue != 0) { for (String line : result) { LOG.error(line); } throw new Exception("Segmenter return code indicated failure: " + exitValue); } } catch (InterruptedException e) { throw new Exception("Segmenter process interrupted by another thread", e); } catch (ExecutionException ee) { throw new Exception("Something went wrong parsing Segmenter output", ee); } catch (TimeoutException te) { // We could not get the result before timeout throw new Exception("Segmenter process timed out", te); } catch (RuntimeException re) { // Unexpected output from Segmenter throw new Exception("Something went wrong parsing Segmenter output", re); } finally { if (process != null) { process.destroy(); } } LOG.debug("transcoding finished"); }
From source file:abs.backend.erlang.ErlangTestDriver.java
/** * Complies code in workDir// w ww .j a v a 2s. c om */ private void make(File workDir) throws Exception { ProcessBuilder pb = new ProcessBuilder("erl", "-pa", "ebin", "-noshell", "-noinput", "-eval", "case make:all() of up_to_date -> halt(0); _ -> halt(1) end."); pb.directory(workDir); pb.inheritIO(); Process p = pb.start(); Assert.assertEquals("Compile failed", 0, p.waitFor()); }