List of usage examples for java.lang Process getErrorStream
public abstract InputStream getErrorStream();
From source file:io.github.jeremgamer.preview.actions.Launch.java
private void launch() { try {//from w w w . j ava 2 s . com extractNatives(); } catch (IOException e1) { e1.printStackTrace(); } final Gson gson = new Gson(); List<String> command = new ArrayList<String>(); command.add(JAVA_DIR); command.add("-Djava.library.path=" + VANILLA_NATIVE_DIR.replaceAll("<version>", "1.8.1")); command.add("-cp"); command.add(LIBRARIES + VANILLA_PATH.replaceAll("<version>", "1.8.1")); command.add(MAIN_CLASS); command.add("--username=" + name); command.add("--version=1.8.1"); command.add("--gameDir=" + VANILLA_GAME_DIRECTORY); command.add("--assetsDir=" + VANILLA_GAME_DIRECTORY + "\\assets"); command.add("--assetIndex=" + "1.8.1"); command.add("--uuid=" + userID); command.add("--accessToken=" + accessToken); command.add("--userProperties=" + gson.toJson(user)); command.add("--userType=mojang"); for (String s : command) { System.out.println(s); } try { ProcessBuilder pb = new ProcessBuilder(command.toArray(new String[command.size()])) .directory(new File(VANILLA_GAME_DIRECTORY)); final Process process = pb.start(); StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR"); errorGobbler.start(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.netflix.dynomitemanager.defaultimpl.FloridaProcessManager.java
void logProcessOutput(Process p) { try {/*from ww w .j a v a 2 s .co m*/ final String stdOut = readProcessStream(p.getInputStream()); final String stdErr = readProcessStream(p.getErrorStream()); logger.info("std_out: {}", stdOut); logger.info("std_err: {}", stdErr); } catch (IOException ioe) { logger.warn("Failed to read the std out/err streams", ioe); } }
From source file:de.rinderle.softvis3d.layout.dot.ExecuteCommand.java
public String executeCommandReadAdot(final String command, final String inputGraph, final Version currentVersion) throws DotExecutorException { final Process process; try {//from ww w.j a va2s . co m process = Runtime.getRuntime().exec(command); writeStringToOutput(inputGraph, process); final String errorOutput = readOutputStream(process.getErrorStream()); if (!StringUtils.isEmpty(errorOutput)) { throw new DotExecutorException(errorOutput); } return readAdotStream(currentVersion, process); } catch (final IOException e) { throw new DotExecutorException(e.getMessage(), e); } catch (final InterruptedException e) { throw new DotExecutorException(e.getMessage(), e); } }
From source file:com.impetus.kundera.ycsb.runner.YCSBRunner.java
public void run(final String workLoad, final int threadCount) throws IOException { int runCounter = crudUtils.getMaxRunSequence(new Date(), runType); runCounter = runCounter + 1;/* w ww. j a v a2 s.c o m*/ noOfThreads = threadCount; // id column of performanceNoInfo table Date id = new Date(); int counter = 1; for (String client : clients) { currentClient = client; if (clientjarlocation != null && ycsbJarLocation != null && client != null && runType != null && host != null && schema != null && columnFamilyOrTable != null) { Runtime runtime = Runtime.getRuntime(); counter++; String runCommand = getCommandString(client, workLoad); logger.info(runCommand); double totalTime = 0.0; long noOfOperations = 0; Process process = runtime.exec(runCommand); process.getErrorStream(); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line = null; BigDecimal avgLatency = null; BigDecimal throughput = null; boolean processed = false; while ((line = br.readLine()) != null) { processed = true; if (line.contains("RunTime")) { totalTime = Double.parseDouble(line.substring(line.lastIndexOf(", ") + 2)); logger.info("Total time taken " + totalTime); } if (line.contains("Operations") && noOfOperations == 0) { noOfOperations = Long.parseLong(line.substring(line.lastIndexOf(", ") + 2)); logger.info("Total no of oprations " + noOfOperations); } if (line.contains("Throughput")) { throughput = new BigDecimal(line.substring(line.lastIndexOf(", ") + 2)); logger.info("Throughput(ops/sec) " + line); } if (line.contains("AverageLatency")) { if (avgLatency == null) { avgLatency = new BigDecimal(line.substring(line.lastIndexOf(", ") + 2)); logger.info("AverageLatency " + line); } } /* * if(line.contains("MinLatency")) { * logger.info("MinLatency " + line); } * if(line.contains("MaxLatency")) { * logger.info("MaxLatency " + line); } */ // if(!(line.contains("CLEANUP") || line.contains("UPDATE") // || line.contains("INSERT") )){ // logger.info(line); // } } if (!processed) { is = process.getErrorStream(); isr = new InputStreamReader(is); br = new BufferedReader(isr); line = null; while ((line = br.readLine()) != null) { logger.info(line); } throw new RuntimeException("Error while processing"); } PerformanceNoInfo info = new PerformanceNoInfo(id, releaseNo, client.substring(client.lastIndexOf(".") + 1), runType, noOfThreads, noOfOperations, totalTime, runCounter); if (avgLatency != null) { info.setAvgLatency(avgLatency.round(MathContext.DECIMAL32)); } if (throughput != null) { info.setThroughput(throughput.round(MathContext.DECIMAL32)); } crudUtils.persistInfo(info); timeTakenByClient.put(client, throughput); } } sendMail(); }
From source file:de.unibremen.informatik.tdki.combo.rewriting.FakeFilterRewriter.java
private void printOutput(Process p) throws IOException { String line;/* ww w . ja v a 2s . c o m*/ BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream())); while ((line = bri.readLine()) != null) { System.out.println(line); } bri.close(); while ((line = bre.readLine()) != null) { System.out.println(line); } bre.close(); }
From source file:io.apiman.common.es.util.ApimanEmbeddedElastic.java
private void checkForDanglingProcesses() throws IOException { if (Files.exists(pidPath)) { for (String pid : Files.readAllLines(pidPath)) { System.err.println(//from w w w.j a v a2 s. com "Attempting to kill Elasticsearch process left over from previous execution: " + pid); Process result = Runtime.getRuntime().exec("kill " + pid); IOUtils.copy(result.getInputStream(), System.out); IOUtils.copy(result.getErrorStream(), System.err); result.destroy(); } Files.deleteIfExists(pidPath); } }
From source file:at.ait.dme.yuma.server.image.WebsiteCaptureServiceImpl.java
@Override public String captureSite(String url) throws WebsiteCaptureException { String imageName = ""; try {//from w w w . j ava 2 s.c om imageName = new Long(System.currentTimeMillis()).toString() + ".jpg"; String filename = targetPath + "/" + imageName; Process p = Runtime.getRuntime() .exec("cutycapt --min-width=" + minWidth.toString() + " --url=" + url + " --out=" + filename); if (p.waitFor() != 0) { String errorMessage = ""; InputStream errorStream = p.getErrorStream(); if (errorStream != null) errorMessage = IOUtils.toString(errorStream, "UTF-8"); throw new WebsiteCaptureException("failed to capture site: " + errorMessage); } } catch (Throwable t) { logger.fatal(t.getMessage(), t); throw new WebsiteCaptureException(t); } return RELATIVE_IMAGEURL_PATH + "/" + imageName; }
From source file:net.sourceforge.subsonic.service.metadata.FFmpegParser.java
/** * Parses meta data for the given music file. No guessing or reformatting is done. * * * @param file The music file to parse./*from w w w. ja va 2 s . com*/ * @return Meta data for the file. */ @Override public MetaData getRawMetaData(File file) { MetaData metaData = new MetaData(); try { File ffmpeg = new File(transcodingService.getTranscodeDirectory(), "ffmpeg"); String[] command = new String[] { ffmpeg.getAbsolutePath(), "-i", file.getAbsolutePath() }; Process process = Runtime.getRuntime().exec(command); InputStream stdout = process.getInputStream(); InputStream stderr = process.getErrorStream(); // Consume stdout, we're not interested in that. new InputStreamReaderThread(stdout, "ffmpeg", true).start(); // Read everything from stderr. It will contain text similar to: // Input #0, avi, from 'foo.avi': // Duration: 00:00:33.90, start: 0.000000, bitrate: 2225 kb/s // Stream #0.0: Video: mpeg4, yuv420p, 352x240 [PAR 1:1 DAR 22:15], 29.97 fps, 29.97 tbr, 29.97 tbn, 30k tbc // Stream #0.1: Audio: pcm_s16le, 44100 Hz, 2 channels, s16, 1411 kb/s String[] lines = StringUtil.readLines(stderr); Integer width = null; Integer height = null; Double par = 1.0; for (String line : lines) { Matcher matcher = DURATION_PATTERN.matcher(line); if (matcher.find()) { int hours = Integer.parseInt(matcher.group(1)); int minutes = Integer.parseInt(matcher.group(2)); int seconds = Integer.parseInt(matcher.group(3)); metaData.setDurationSeconds(hours * 3600 + minutes * 60 + seconds); } matcher = BITRATE_PATTERN.matcher(line); if (matcher.find()) { metaData.setBitRate(Integer.valueOf(matcher.group(1))); } matcher = DIMENSION_PATTERN.matcher(line); if (matcher.find()) { width = Integer.valueOf(matcher.group(1)); height = Integer.valueOf(matcher.group(2)); } // PAR = Pixel Aspect Rate matcher = PAR_PATTERN.matcher(line); if (matcher.find()) { int a = Integer.parseInt(matcher.group(1)); int b = Integer.parseInt(matcher.group(2)); if (a > 0 && b > 0) { par = (double) a / (double) b; } } } if (width != null && height != null) { width = (int) Math.round(width.doubleValue() * par); metaData.setWidth(width); metaData.setHeight(height); } } catch (Throwable x) { LOG.warn("Error when parsing metadata in " + file, x); } return metaData; }
From source file:org.dlut.mycloudserver.service.storemanage.impl.DiskManageServiceImpl.java
/** * ntfs?//from www. ja va 2s. c om * * @param diskPath * @return */ private boolean formatDiskToNtfs(String diskPath) { try { //sudo???????? String command = "sudo virt-format -a " + diskPath + " --filesystem=ntfs "; log.info("" + command); Process process = Runtime.getRuntime().exec(command); InputStream stderr = process.getErrorStream(); InputStreamReader isr = new InputStreamReader(stderr); BufferedReader br = new BufferedReader(isr); String line = null; log.info("formating disk " + diskPath + " ..."); while ((line = br.readLine()) != null) { log.info("error message " + line); } int exitVal = process.waitFor(); if (exitVal != 0) { return false; } log.info("success to format disk" + diskPath); return true; } catch (Exception e) { log.info("error message " + e.toString()); return false; } // Process process; // try { // process = Runtime.getRuntime().exec(command);//?linux // process.waitFor(); // if (process.exitValue() == 0) { // return true; // } // } catch (IOException e) { // log.error("error message", e); // } catch (InterruptedException e) { // // TODO Auto-generated catch block // log.error("error message", e); // } // return false; }
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 ww w. j a va 2 s . c o 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; }