List of usage examples for java.lang ProcessBuilder start
public Process start() throws IOException
From source file:com.thoughtworks.gauge.maven.GaugeExecutionMojo.java
private void executeGaugeSpecs() throws GaugeExecutionFailedException { try {/*from w ww.j a v a 2 s . c om*/ ProcessBuilder builder = createProcessBuilder(); debug("Executing => " + builder.command()); Process process = builder.start(); Util.InheritIO(process.getInputStream(), System.out); Util.InheritIO(process.getErrorStream(), System.err); if (process.waitFor() != 0) { throw new GaugeExecutionFailedException(); } } catch (InterruptedException e) { throw new GaugeExecutionFailedException(e); } catch (IOException e) { throw new GaugeExecutionFailedException(e); } }
From source file:com.linkedin.restli.tools.idlgen.TestRestLiResourceModelExporter.java
private void compareFiles(String actualFileName, String expectedFileName) throws Exception { String actualContent = readFile(actualFileName); String expectedContent = readFile(expectedFileName); if (!actualContent.trim().equals(expectedContent.trim())) { // Ugh... gradle PrintStream actualStdout = new PrintStream(new FileOutputStream(FileDescriptor.out)); actualStdout.println(//ww w . j ava2 s. c o m "ERROR " + actualFileName + " does not match " + expectedFileName + " . Printing diff..."); try { // TODO environment dependent, not cross platform ProcessBuilder pb = new ProcessBuilder("diff", expectedFileName, actualFileName); pb.redirectErrorStream(); Process p = pb.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; while ((line = reader.readLine()) != null) { actualStdout.println(line); // System.out.println(line); } } catch (Exception e) { // TODO Setup log4j, find appropriate test harness used in R2D2 actualStdout.println("Error printing diff: " + e.getMessage()); } fail(actualFileName + " does not match " + expectedFileName); } }
From source file:de.cologneintelligence.fitgoodies.maven.FitIntegrationTestMojo.java
private void startProcess(ProcessBuilder builder) throws MojoExecutionException { try {// w ww . j a v a2 s. c o m Process process = builder.start(); new StreamLogger(process.getErrorStream(), true, getLog()).start(); new StreamLogger(process.getInputStream(), false, getLog()).start(); int result = process.waitFor(); boolean success = result == 0; saveResult(success); if (!success) { getLog().info("One or more fit test(s) failed with return code " + result + ". Will fail in verify phase!"); } } catch (Exception e) { throw new MojoExecutionException("Error while running fit", e); } }
From source file:au.edu.unsw.cse.soc.federatedcloud.community.driven.cloudbase.connectors.docker.DockerConnector.java
@Override public Result deploy(int resourceID) { String scriptFileLocation = "./tmp/" + resourceID + ".sh"; //run the deployment script ProcessBuilder pb = new ProcessBuilder(scriptFileLocation); Map<String, String> env = pb.environment(); pb.directory(new File(".")); try {/*from w ww . j a v a 2 s. co m*/ Process p = pb.start(); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); // read the output from the command System.out.println("Here is the standard output of the command:\n"); String s = null; while ((s = stdInput.readLine()) != null) { log.info(s); } // read any errors from the attempted command System.out.println("Here is the standard error of the command (if any):\n"); while ((s = stdError.readLine()) != null) { log.info(s); } } catch (IOException e) { log.error(e.getMessage(), e); } return null; }
From source file:com.salsaw.msalsa.clustal.ClustalOmegaManager.java
@Override public void callClustal(String clustalPath, ClustalFileMapper clustalFileMapper) throws IOException, InterruptedException, SALSAException { // Get program path to execute List<String> clustalProcessCommands = new ArrayList<String>(); clustalProcessCommands.add(clustalPath); // Create the name of output files String inputFileName = FilenameUtils.getBaseName(clustalFileMapper.getInputFilePath()); String inputFileFolderPath = FilenameUtils.getFullPath(clustalFileMapper.getInputFilePath()); Path alignmentFilePath = Paths.get(inputFileFolderPath, inputFileName + "-aln.fasta"); Path guideTreeFilePath = Paths.get(inputFileFolderPath, inputFileName + "-tree.dnd"); // Set inside file mapper clustalFileMapper.setAlignmentFilePath(alignmentFilePath.toString()); clustalFileMapper.setGuideTreeFilePath(guideTreeFilePath.toString()); setClustalFileMapper(clustalFileMapper); // Create clustal omega data generateClustalArguments(clustalProcessCommands); // http://www.rgagnon.com/javadetails/java-0014.html ProcessBuilder builder = new ProcessBuilder(clustalProcessCommands); builder.redirectErrorStream(true);//from ww w . j ava 2 s .co m System.out.println(builder.command()); final Process process = builder.start(); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line; while ((line = br.readLine()) != null) { System.out.println(line); } process.waitFor(); if (process.exitValue() != 0) { throw new SALSAException("Failed clustal omega call"); } }
From source file:com.devbury.mkremote.server.QuickLaunchServiceImpl.java
protected void runOnWindows(File f) throws Throwable { logger.debug("Windows launch failed. Trying work arounds"); String extention = f.getName().substring(f.getName().lastIndexOf(".")); ProcessBuilder pb = new ProcessBuilder("cmd", "/C", "assoc", extention); Process proc = pb.start(); Properties p = new Properties(); p.load(new BackslashFilterInputStream(proc.getInputStream())); String type = p.getProperty(extention); pb = new ProcessBuilder("cmd", "/C", "ftype", type); proc = pb.start();/*from ww w. j a v a2 s . co m*/ p = new Properties(); p.load(new BackslashFilterInputStream(proc.getInputStream())); String exe = p.getProperty(type); logger.debug("exe is {}", exe); // see if windows media player is supposed to run this if (exe.toLowerCase().indexOf("wmplayer") != -1) { String program_files = System.getenv("ProgramFiles"); if (program_files == null) { program_files = "C:\\Program Files"; } logger.debug("Using custom windows media player launch"); pb = new ProcessBuilder(program_files + "\\Windows Media Player\\wmplayer.exe", f.getCanonicalPath()); pb.start(); } else { pb = new ProcessBuilder("cmd", "/C", f.getName()); pb.directory(f.getParentFile()); pb.start(); } }
From source file:ch.entwine.weblounge.common.impl.util.process.ProcessExecutor.java
/** * Executes the process. During execution, {@link #onLineRead(String)} will be * called for process output. When finished, {@link #onProcessFinished(int)} * is called./*from w w w .ja v a 2 s. c o m*/ * * @throws ProcessExcecutorException * if an error occurs during execution */ public final void execute() throws ProcessExcecutorException { BufferedReader in = null; Process process = null; StreamHelper errorStreamHelper = null; try { // create process. // no special working directory is set which means the working directory // of the current java process is used. ProcessBuilder pbuilder = new ProcessBuilder(commandLine); pbuilder.redirectErrorStream(redirectErrorStream); process = pbuilder.start(); // Consume error stream if necessary if (!redirectErrorStream) { errorStreamHelper = new StreamHelper(process.getErrorStream()); } // Read input and in = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = in.readLine()) != null) { if (!onLineRead(line)) break; } // wait until the task is finished process.waitFor(); int exitCode = process.exitValue(); onProcessFinished(exitCode); } catch (Throwable t) { String msg = null; if (errorStreamHelper != null) { msg = errorStreamHelper.contentBuffer.toString(); } else { msg = t.getMessage(); } // TODO: What if the error stream has been redirected? Can we still get // the error message? throw new ProcessExcecutorException(msg, t); } finally { if (process != null) process.destroy(); IOUtils.closeQuietly(in); } }
From source file:Good_GUi.java
private void jLabel3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel3MouseClicked box += "Processing...\n"; jTextArea1.setText(box);/*from w ww .ja v a2 s.com*/ String url = jTextField1.getText(); HttpClient httpClient = new DefaultHttpClient(); try { URIBuilder uriBuilder = new URIBuilder("https://eastus2.api.cognitive.microsoft.com/vision/v1.0/ocr"); uriBuilder.setParameter("language", "unk"); uriBuilder.setParameter("detectOrientation ", "true"); URI uri = uriBuilder.build(); HttpPost request = new HttpPost(uri); // Request headers - replace this example key with your valid subscription key. request.setHeader("Content-Type", "application/json"); request.setHeader("Ocp-Apim-Subscription-Key", "43a031e5db9f438aac7c50a7df692016"); // Request body. Replace the example URL with the URL of a JPEG image containing text. StringEntity requestEntity = new StringEntity("{\"url\":\"" + jTextField1.getText() + "\"}"); request.setEntity(requestEntity); HttpResponse response = httpClient.execute(request); HttpEntity entity = response.getEntity(); String s = EntityUtils.toString(entity); ArrayList<String> list = new ArrayList<>(); if (s.contains("Invalid")) { box += "Can't fetch the image @ " + url + "\n"; jTextArea1.setText(box); } else { System.out.println(s); String[] splitted = s.split("}"); for (String c : splitted) { list.add(c.substring(c.lastIndexOf(":") + 2).replaceAll("\"", "")); } String out = ""; for (int i = 0; i < list.size(); i++) { out += list.get(i) + " "; } out.replaceAll(" ", " "); String x = ""; for (int i = 0; i < out.length(); i++) { x += out.substring(i, i + 1); } try { PrintWriter writer = new PrintWriter("ITT.txt", "UTF-8"); writer.println(x); writer.close(); box += "Success! File saved as ITT.txt\n"; jTextArea1.setText(box); ProcessBuilder pb = new ProcessBuilder("Notepad.exe", "ITT.txt"); pb.start(); } catch (IOException e) { box += e.toString(); jTextArea1.setText(box); } Parser p = new Parser(x); p.parse(); StringSelection stringSelection = new StringSelection(p.toString()); java.awt.datatransfer.Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard(); clpbrd.setContents(stringSelection, null); JOptionPane.showMessageDialog(null, "Github data copied to clipboard!"); } } catch (Exception e) { box += e.toString() + "\n"; jTextField1.setText(box); } }
From source file:de.uni_freiburg.informatik.ultimate.licence_manager.authors.SvnAuthorProvider.java
private boolean isUnderVersionControl(String absolutePath) { final ProcessBuilder pbuilder = new ProcessBuilder("svn", "info", absolutePath); try {//from w w w .ja v a 2 s. com final Process process = pbuilder.start(); if (process.waitFor(1000, TimeUnit.MILLISECONDS)) { final List<String> lines = IOUtils.readLines(process.getInputStream(), Charset.defaultCharset()); if (lines == null || lines.isEmpty()) { return false; } return !lines.get(0).contains("is not a working copy"); } } catch (IOException | InterruptedException e) { System.err.println("Could not find 'svn' executable, disabling author provider"); return false; } return false; }
From source file:org.auraframework.archetype.AuraArchetypeSimpleTestMANUAL.java
private Process startProcess(File workingDir, List<String> command) throws Exception { ProcessBuilder builder = new ProcessBuilder(command); builder.directory(workingDir);//from w w w . j a va2 s . c o m builder.redirectErrorStream(true); return builder.start(); }