java.lang.ProcessBuilder Java Examples
The following examples show how to use
java.lang.ProcessBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DaCapoClientRunner.java From dacapobench with Apache License 2.0 | 7 votes |
public static void initialize(String carName, String size, int numThreads, boolean useBeans) { try { car = carName; /* Calling this function directly does not launch the client now. According to testing, it seems the getMain method of boot does not work properlly. Thus these ugly codes are temporarily used fot verifing that the whole framework works Will be changed once the problem is fixed */ //ClientCLI.main(new String[] { car, "-i", "-t", numThreads + "", "-s", size, useBeans ? "-b" : "" }); gero = System.getProperty("org.apache.geronimo.home.dir"); String jhome= System.getProperty("java.home"); ProcessBuilder pb = new ProcessBuilder(jhome + "/bin/java", "-jar", "-Dkaraf.startLocalConsole=false",gero + "/bin/client.jar", car, "-i", "-t", numThreads + "", "-s", size, useBeans ? "-b" : ""); Process p = pb.start(); p.waitFor(); } catch (Exception e) { System.err.print("Exception initializing client: " + e.toString()); e.printStackTrace(); System.exit(-1); } }
Example #2
Source File: DaCapoClientRunner.java From dacapobench with Apache License 2.0 | 5 votes |
public static void runIteration(String size, int numThreads, boolean useBeans) { try { /* Calling the function directly does not launch the client now. According to testing, it seems the getMain method of boot does not work properlly. Thus these ugly codes are temporarily used for checking the whole framework Will be changed once the problem is fixed */ //ClientCLI.main(new String[] { car, "-i", "-t", numThreads + "", "-s", size, useBeans ? "-b" : "" }); String jhome= System.getProperty("java.home"); ProcessBuilder pb = new ProcessBuilder(jhome + "/bin/java", "-jar", "-Dkaraf.startLocalConsole=false", gero + "/bin/client.jar", car, "-t", numThreads + "", "-s", size, useBeans ? "-b" : ""); Process p = pb.start(); p.waitFor(); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); while (stdInput.ready()) { //While there's something in the buffer //read&print - replace with a buffered read (into an array) if the output doesn't contain CR/LF System.out.println(stdInput.readLine()); } } catch (Exception e) { System.err.print("Exception running client iteration: " + e.toString()); e.printStackTrace(); } }
Example #3
Source File: RepairnatorPostBuild.java From repairnator with MIT License | 5 votes |
public void runRepairnator(EnvVars env) throws IOException,InterruptedException{ Config config = this.config; System.out.println("jar location " + config.getJarLocation()); RepairnatorProcessBuilder repProcBuilder = new RepairnatorProcessBuilder() .useJavaExec(config.getJavaExec()) .atJarLocation(config.getJarLocation()) .onGitUrl(config.getGitUrl()) .onGitBranch(config.getGitBranch()) .onGitOAuth(config.getGitOAuth()) .withSmtpUsername(config.getSmtpUsername()) .withSmtpPassword(config.getSmtpPassword()) .withSmtpServer(config.getSmtpServer()) .withSmtpPort(config.getSmtpPort()) .shouldNotifyTo(config.getNotifyTo()) .withRepairTools(config.getTools()) .withSonarRules(config.getSonarRules()) .useSmtpTls(config.useTLSOrSSL()) .asNoTravisRepair() .alsoCreatePR() .withMavenHome(config.getMavenHome()) .atWorkSpace(config.getTempDir().getAbsolutePath()) .withOutputDir(config.getTempDir().getAbsolutePath()); ProcessBuilder builder = repProcBuilder.build().directory(config.getTempDir()); builder.redirectErrorStream(true); builder.inheritIO().redirectOutput(ProcessBuilder.Redirect.PIPE); Process process = builder.start(); this.printProcessOutPut(process); process.waitFor(); }
Example #4
Source File: MyTestUtils.java From semanticvectors with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Spawn a child to execute the main method in Class childMain * using the same args and environment as the current runtime. * This method prevents a child processes from hanging * when its output buffers saturate by creating threads to * empty the output buffers. * @return The process, already started. Consider using waitForAndDestroy() to clean up afterwards. * @param childMain The Class to spawn, must contain main function * @param inputArgs arguments for the main class. Use null to pass no arguments. * @param in The child process will read input from this stream. Use null to avoid reading input. Always close() your stream when you are done or you may deadlock. * @param out The child process will write output to this stream. Use null to avoid writing output. * @param err The child process will write errors to this stream. Use null to avoid writing output. */ public static Process spawnChildProcess( Class<?> childMain, String[] inputArgs, InputStream in, OutputStream out, OutputStream err) throws IOException { //get the same arguments as used to start this JRE RuntimeMXBean rmxb = ManagementFactory.getRuntimeMXBean(); List<String> arglist = rmxb.getInputArguments(); String cp = rmxb.getClassPath(); //construct "java <arguments> <main-class-name>" ArrayList<String> arguments = new ArrayList<String>(arglist); arguments.add(0, "java"); arguments.add("-classpath"); arguments.add(cp); arguments.add(childMain.getCanonicalName()); for (String arg : inputArgs) arguments.add(arg); //using ProcessBuilder initializes the child process with parent's env. ProcessBuilder pb = new ProcessBuilder(arguments); //redirecting STDERR to STDOUT needs to be done before starting if (err == out) { pb.redirectErrorStream(true); } Process proc; proc = pb.start(); //Might throw an IOException to calling method //setup stdin if (in != null) { new OutputReader(in, proc.getOutputStream()).start(); } //setup stdout if (out == null) { out = new NullOutputStream(); } new OutputReader(proc.getInputStream(), out).start(); //setup stderr if (!pb.redirectErrorStream()) { if (err == null) { err = new NullOutputStream(); } new OutputReader(proc.getErrorStream(), err).start(); } return proc; }
Example #5
Source File: RepairnatorProcessBuilder.java From repairnator with MIT License | 4 votes |
public ProcessBuilder build() { this.checkValid(); cmdList.add(this.javaExec); cmdList.add("-jar"); cmdList.add("-Dspoon.log.path=" + this.outputDir + File.separator + "spoon-log.log"); cmdList.add("-Dlogs_dir=" + this.outputDir); cmdList.add(this.jarLocation); cmdList.add("--launcherChoice"); cmdList.add("NEW"); cmdList.add("--launcherMode"); cmdList.add("GIT_REPOSITORY"); cmdList.add("--output"); cmdList.add(this.outputDir); cmdList.add("--MavenHome"); cmdList.add(this.mavenHome); cmdList.add("--workspace"); cmdList.add(this.workspace); cmdList.add("--gitrepourl"); cmdList.add(this.gitUrl); cmdList.add("--gitrepobranch"); cmdList.add(this.gitBranch); cmdList.add("--repairTools"); cmdList.add(String.join(",",this.repairTools)); if (!sonarRules.equals("") || sonarRules != null) { cmdList.add("--sonarRules"); cmdList.add(this.sonarRules); } if (this.notifyTo != null && !this.notifyTo.equals("")) { if (this.smtpUsername != null && !this.smtpUsername.equals("")) { cmdList.add("--smtpUsername"); cmdList.add(this.smtpUsername); } if (this.smtpPassword != null && !this.smtpPassword.equals("")) { cmdList.add("--smtpPassword"); cmdList.add(this.smtpPassword); } if (this.smtpServer != null && !this.smtpServer.equals("")) { cmdList.add("--smtpServer"); cmdList.add(this.smtpServer); } if (this.smtpPort != null && !this.smtpPort.equals("")) { cmdList.add("--smtpPort"); cmdList.add(this.smtpPort); } cmdList.add("--notifyto"); cmdList.add(String.join(",",this.notifyTo)); } cmdList.add("--gitrepo"); if (this.useSmtpTLS) { cmdList.add("--smtpTLS"); } if(!(this.gitOAuth.equals("") || this.gitOAuth == null)) { cmdList.add("--ghOauth"); cmdList.add(this.gitOAuth); cmdList.add("--createPR"); } return new ProcessBuilder(this.cmdList).inheritIO(); }
Example #6
Source File: JAudioFile.java From jAudioGIT with GNU Lesser General Public License v2.1 | 4 votes |
public static void main(String[] args) throws Exception{ processor = new AudioStreamProcessor(args[0],args[1]); String base_prefix =args[2]; base_prefix += args[4]; ProcessBuilder gstreamerBuilder = new ProcessBuilder("gst-launch-1.0", "-q", "filesrc", "location="+args[3], "!", "decodebin", "!", "audioconvert", "!", "audio/x-raw,format=F32LE", "!", "fdsink"); Process gstreamer = gstreamerBuilder.start(); DataInputStream input = new DataInputStream(gstreamer.getInputStream()); ByteBuffer buffer = ByteBuffer.allocateDirect(1000000000); buffer.order(java.nio.ByteOrder.LITTLE_ENDIAN); byte[] b = new byte[1000000]; int read=0; int total=0; while((read = input.read(b))>-1){ total += read; if(read > 0) buffer.put(b,0,read); } System.out.println(); buffer.flip(); FloatBuffer db = buffer.asFloatBuffer(); double[] samples = new double[total / 8]; for(int i=0;i<samples.length;++i){ samples[i] = (db.get()+db.get()) / 2.0; } db = null; buffer = null; double max=0.0; double min=0.0; boolean okay = false; if(samples.length < 512){ throw new Exception("File is too small to analyze - "+samples.length+" samples"); } for(int i=0;i<samples.length;++i){ if((samples[i] > 1.0) || (samples[i] < -1.0)){ throw new Exception("Badly formatted data "+i+" "+samples[i]); } if((samples[i] > 0.7)){ okay = true; } } if(!okay){ throw new Exception("Data is artificially small - probable endianess problem"); } processor.process(samples); Date date = new Date(); String attach = date.toString(); attach = Pattern.compile("\\s").matcher(attach).replaceAll("_"); base_prefix += Pattern.compile(":").matcher(attach).replaceAll("-"); processor.output(base_prefix); }