List of usage examples for java.lang ProcessBuilder start
public Process start() throws IOException
From source file:cz.cuni.mff.ksi.jinfer.autoeditor.BububuEditor.java
/** * Draws automaton and waits until user picks two states and clicks * 'continue' button.// w ww .ja v a2s . co m * * @param automaton automaton to be drawn * @return if user picks exactly two states returns Pair of them otherwise null */ @Override public List<State<T>> drawAutomatonToPickStates(final Automaton<T> automaton) { final DirectedSparseMultigraph<State<T>, Step<T>> graph = new DirectedSparseMultigraph<State<T>, Step<T>>(); final Map<State<T>, Set<Step<T>>> automatonDelta = automaton.getDelta(); // Get vertices = states of automaton for (Entry<State<T>, Set<Step<T>>> entry : automatonDelta.entrySet()) { graph.addVertex(entry.getKey()); } // Get edges of automaton for (Entry<State<T>, Set<Step<T>>> entry : automatonDelta.entrySet()) { for (Step<T> step : entry.getValue()) { graph.addEdge(step, step.getSource(), step.getDestination()); } } Map<State<T>, Point2D> positions = new HashMap<State<T>, Point2D>(); ProcessBuilder p = new ProcessBuilder(Arrays.asList("/usr/bin/dot", "-Tplain")); try { Process k = p.start(); k.getOutputStream().write((new AutomatonToDot<T>()).convertToDot(automaton, symbolToString).getBytes()); k.getOutputStream().flush(); BufferedReader b = new BufferedReader(new InputStreamReader(k.getInputStream())); k.getOutputStream().close(); Scanner s = new Scanner(b); s.next(); s.next(); double width = s.nextDouble(); double height = s.nextDouble(); double windowW = 500; double windowH = 300; while (s.hasNext()) { if (s.next().equals("node")) { int nodeName = s.nextInt(); double x = s.nextDouble(); double y = s.nextDouble(); for (State<T> state : automatonDelta.keySet()) { if (state.getName() == nodeName) { positions.put(state, new Point((int) (windowW * x / width), (int) (windowH * y / height))); break; } } } } } catch (IOException ex) { Exceptions.printStackTrace(ex); } Transformer<State<T>, Point2D> trans = TransformerUtils.mapTransformer(positions); // TODO rio find suitable layout final Layout<State<T>, Step<T>> layout = new StaticLayout<State<T>, Step<T>>(graph, trans); //layout.setSize(new Dimension(300,300)); // sets the initial size of the space visualizationViewer = new VisualizationViewer<State<T>, Step<T>>(layout); //visualizationViewer.setPreferredSize(new Dimension(350,350)); //Sets the viewing area size visualizationViewer.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<State<T>>()); visualizationViewer.getRenderContext().setEdgeLabelTransformer(new Transformer<Step<T>, String>() { @Override public String transform(Step<T> i) { return BububuEditor.this.symbolToString.toString(i.getAcceptSymbol()); } }); final PluggableGraphMouse gm = new PluggableGraphMouse(); gm.add(new PickingUnlimitedGraphMousePlugin<State<T>, Step<T>>()); visualizationViewer.setGraphMouse(gm); // Call GUI in a special thread. Required by NB. synchronized (this) { WindowManager.getDefault().invokeWhenUIReady(new Runnable() { @Override public void run() { // Pass this as argument so the thread will be able to wake us up. AutoEditorTopComponent.findInstance().drawAutomatonBasicVisualizationServer(BububuEditor.this, visualizationViewer, "Please select two states to be merged together."); } }); try { // Sleep on this. this.wait(); } catch (InterruptedException e) { return null; } } /* AutoEditorTopComponent wakes us up. Get the result and return it. * VisualizationViewer should give us the information about picked vertices. */ final Set<State<T>> pickedSet = visualizationViewer.getPickedVertexState().getPicked(); List<State<T>> lst = new ArrayList<State<T>>(pickedSet); return lst; }
From source file:hydrograph.ui.perspective.ApplicationWorkbenchWindowAdvisor.java
private void serviceInitiator(Properties properties) throws IOException { if (OSValidator.isWindows()) { //Updated the java classpath to include the dependent jars String path = ""; try {//from w ww .jav a 2 s . c om path = Paths.get(Platform.getInstallLocation().getURL().toURI()).toString() + "\\"; } catch (URISyntaxException e) { // TODO Auto-generated catch block logger.error(e.getMessage()); } logger.debug(Platform.getInstallLocation().getURL().getPath()); String command = "java -cp \"" + getInstallationConfigPath().trim() + ";" + path + properties.getProperty(SERVICE_DEPENDENCIES) + ";" + path + properties.getProperty(SERVICE_JAR) + "\" " + properties.getProperty(DRIVER_CLASS); logger.debug("Starting server with command - " + command); ProcessBuilder builder = new ProcessBuilder(new String[] { "cmd", "/c", command }); builder.start(); } else if (OSValidator.isMac()) { logger.debug("On Mac Operating System...."); //Updated the java classpath to include the dependent jars String command = "java -cp " + getInstallationConfigPath().trim() + ":" + Platform.getInstallLocation().getURL().getPath() + properties.getProperty(SERVICE_JAR) + ":" + Platform.getInstallLocation().getURL().getPath() + properties.getProperty(SERVICE_DEPENDENCIES) + " " + properties.getProperty(DRIVER_CLASS); logger.debug("command{}", command); ProcessBuilder builder = new ProcessBuilder(new String[] { "bash", "-c", command }); builder.start(); } else if (OSValidator.isUnix()) { new ProcessBuilder(new String[] { "java", "-jar", properties.getProperty(SERVICE_JAR) }).start(); } else if (OSValidator.isSolaris()) { } }
From source file:com.diversityarrays.kdxplore.trialdesign.RscriptFinderPanel.java
private void doCheckScriptPath() { String scriptPath = scriptPathField.getText().trim(); BackgroundTask<Either<String, String>, Void> task = new BackgroundTask<Either<String, String>, Void>( "Checking...", true) { @Override//from w w w . j a v a2 s. c om public Either<String, String> generateResult(Closure<Void> arg0) throws Exception { ProcessBuilder findRScript = new ProcessBuilder(scriptPath, "--version"); Process p = findRScript.start(); while (!p.waitFor(1000, TimeUnit.MILLISECONDS)) { if (backgroundRunner.isCancelRequested()) { p.destroy(); throw new CancellationException(); } } if (0 == p.exitValue()) { String output = Algorithms.readContent(null, p.getInputStream()); versionNumber = Algorithms.readContent(null, p.getErrorStream()); return Either.right(output); } errorOutput = Algorithms.readContent("Error Output:", p.getErrorStream()); if (errorOutput.isEmpty()) { errorOutput = "No error output available"; return Either.left(errorOutput); } return Either.left(errorOutput); } @Override public void onException(Throwable t) { onScriptPathChecked.accept(Either.left(t)); } @Override public void onCancel(CancellationException ce) { onScriptPathChecked.accept(Either.left(ce)); } @Override public void onTaskComplete(Either<String, String> either) { if (either.isLeft()) { MsgBox.error(RscriptFinderPanel.this, either.left(), "Error Output"); } else { TrialDesignPreferences.getInstance().setRscriptPath(scriptPath); onScriptPathChecked.accept(Either.right(scriptPath)); checkOutput = either.right(); } } }; backgroundRunner.runBackgroundTask(task); }
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 www . j av a 2 s .com*/ 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:nl.bneijt.javapjson.JavapJsonMojo.java
private String runJavap(File classFile) throws MojoExecutionException { File classDirectory = classFile.getParentFile(); String classFileName = classFile.getName(); ProcessBuilder psBuilder = new ProcessBuilder("javap", "-l", classFileName.substring(0, classFileName.length() - CLASS_EXTENSION.length())); psBuilder.directory(classDirectory); Process process;//w w w . j ava 2 s. co m try { process = psBuilder.start(); } catch (IOException e1) { throw new MojoExecutionException("Could not start process builder", e1); } try { process.getOutputStream().close(); } catch (IOException e) { throw new MojoExecutionException("Could not close output stream while executing javap"); } try { byte[] buffer = new byte[1024]; IOUtils.read(process.getInputStream(), buffer); return new String(buffer); } catch (IOException e) { throw new MojoExecutionException( "Could not read all input from command javap while reading \"" + classFile + "\""); } }
From source file:cz.cas.lib.proarc.common.process.AsyncProcess.java
@Override public void run() { done.set(false);/*from w ww.j a va2 s . c o m*/ outputConsumer = null; exitCode = -1; ProcessBuilder pb = new ProcessBuilder(cmdLine); // for now redirect outputs into a single stream to eliminate // the need to run multiple threads to read each output pb.redirectErrorStream(true); pb.environment().putAll(env); try { Process process = pb.start(); refProcess.set(process); outputConsumer = new OutputConsumer(process.getInputStream()); outputConsumer.start(); exitCode = process.waitFor(); LOG.fine("Done " + cmdLine); } catch (Exception ex) { LOG.log(Level.SEVERE, cmdLine.toString(), ex); } finally { done.set(true); } }
From source file:io.fabric8.spi.process.AbstractProcessHandler.java
protected void startProcess(ProcessBuilder processBuilder, ProcessOptions options) throws IOException { process = processBuilder.start(); new Thread(new ConsoleConsumer(process, options)).start(); }
From source file:com.qhrtech.emr.launcher.TemplateLauncherManager.java
private void doRefresh() { synchronized (eventLock) { try {//from ww w .j a va 2s . co m doGeneration(); if (notifyCommand != null) { ProcessBuilder pb = new ProcessBuilder(notifyCommand); pb.redirectError(ProcessBuilder.Redirect.INHERIT); pb.redirectOutput(ProcessBuilder.Redirect.INHERIT); pb.start().waitFor(); } } catch (Exception ex) { LoggerFactory.getLogger(getClass()).error("Error reloading templates.", ex); } } }
From source file:com.sixt.service.framework.ServiceProperties.java
/** * If running in docker, use that; else, generate test_service *//* w w w . j av a 2 s .com*/ private void parseServiceInstance() { try { ProcessBuilder pb = new ProcessBuilder("bash", "-c", "cat /proc/self/cgroup | grep docker | sed 's/^.*\\///' | tail -n1 | cut -c 1-12"); Process p = pb.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String output = reader.readLine(); if (!StringUtils.isBlank(output)) { serviceInstanceId = output.trim(); } p.waitFor(); } catch (Exception e) { logger.error("Error getting docker container id", e); } if ("unknown".equals(serviceInstanceId)) { serviceInstanceId = UUID.randomUUID().toString().replaceAll("-", "").substring(0, 12); } }
From source file:de.phoenix.submission.SubmissionCompilerAndTest.java
@Override public PhoenixSubmissionResult controlSubmission(TaskSubmission submission) { SubmissionTask task = new SubmissionTask(); File dir = PhoenixApplication.submissionPipelineDir; List<String> commands = getCommands(); // Check, if all necessary classes are submitted Set<String> classes = new HashSet<String>(); for (Text text : submission.getTask().getTexts()) { classes.add(text.getTitle());/*from w ww . ja v a 2s .co m*/ } for (Text clazz : submission.getTexts()) { task.addClass(clazz.convert()); classes.remove(clazz.getTitle()); } // Some to implement classes are missing -> error if (!classes.isEmpty()) { return new PhoenixSubmissionResult(SubmissionStatus.MISSING_FILES, "Missing classes to implement/submit. Maybe you wrote the name of the class wrong? Missing Classes:\r\n" + classes.toString()); } if (submission.getTask().isAutomaticTest()) { for (TaskTest test : submission.getTask().getTaskTests()) { addTest(task, test); } } // TODO: Add libraries ProcessBuilder builder = new ProcessBuilder(commands); builder.directory(dir); File errorLog = new File(dir, "error.log"); errorLog.delete(); builder.redirectError(errorLog); try { Process process = builder.start(); JSON_MAPPER.writeValue(process.getOutputStream(), task); process.getOutputStream().close(); PhoenixSubmissionResult result = JSON_MAPPER.readValue(process.getInputStream(), PhoenixSubmissionResult.class); return result; } catch (Exception e) { DebugLog.log(e); } return new PhoenixSubmissionResult(SubmissionStatus.OK, "Fine"); }