List of usage examples for java.lang Process waitFor
public abstract int waitFor() throws InterruptedException;
From source file:SwiftWork.java
/** * Generate a random file of size: blocksize * count * @param blocksize c =1, w =2, b =512, K =1024, M =1024*1024, G =1024*1024*1024, * @param count c =1, w =2, b =512, K =1024, M =1024*1024, G =1024*1024*1024, * @return file name//from ww w. j a v a 2s. com */ public static String generateRandomFile(String blocksize, String count) { Process p; File tmpdir = new File(getBenchITTemp()); if (!tmpdir.isDirectory()) if (!tmpdir.mkdirs()) System.out.println("BenchIT tmpdir is not created. Going to blow up!"); String randfilename = generateFileName("swift"); String randfileaddr = tmpdir.getPath() + "/" + randfilename; try { String command = "/bin/dd if=/dev/urandom of=" + randfileaddr + " bs=" + blocksize + " count=" + count; p = Runtime.getRuntime().exec(command); p.waitFor(); System.out.println("Random File:" + randfileaddr + " with size: (" + blocksize + " x " + count + ") is created successfully"); appendToLocalTmpList(randfileaddr, true); return randfilename; } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } return null; }
From source file:fi.hsl.parkandride.front.ProtractorTest.java
@Test public void protractor_tests() throws InterruptedException, IOException { File projectDir = new File(System.getProperty("user.dir")); if (projectDir.getName().equals("application")) { projectDir = projectDir.getParentFile(); }/*w w w . j a v a2s . c om*/ File script = new File(projectDir, "etc/protractor/protractor.sh"); ProcessBuilder builder = new ProcessBuilder("bash", script.getAbsolutePath(), "test", "--browser=" + browser, "--baseUrl=http://localhost:" + port).inheritIO(); Process process = builder.start(); if (process.waitFor() != 0) { Assert.fail("Protractor tests failed"); } }
From source file:edu.cwru.jpdg.Javac.java
/** * Compiles the java.//from ww w. j av a 2s . co m */ public static List<String> javac(String basepath, String name, String s) { Path dir = Paths.get(cwd).resolve(basepath); if (Files.notExists(dir)) { create_dir(dir); } Path java = dir.resolve(name + ".java"); Path build = dir.resolve("build"); if (!Files.notExists(build)) { try { FileUtils.deleteDirectory(build.toFile()); } catch (IOException e) { throw new RuntimeException("Couldn't rm -r build dir"); } } create_dir(build); byte[] bytes = s.getBytes(); try { Files.write(java, bytes); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } try { Process p = Runtime.getRuntime() .exec(new String[] { "javac", "-d", build.toString(), java.toString() }); String line; BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream())); List<String> stdout_lines = new ArrayList<String>(); line = stdout.readLine(); while (line != null) { stdout_lines.add(line); line = stdout.readLine(); } BufferedReader stderr = new BufferedReader(new InputStreamReader(p.getErrorStream())); List<String> stderr_lines = new ArrayList<String>(); line = stderr.readLine(); while (line != null) { stderr_lines.add(line); line = stderr.readLine(); } if (p.waitFor() != 0) { System.err.println(StringUtils.join(stdout_lines, "\n")); System.err.println("-------------------------------------"); System.err.println(StringUtils.join(stderr_lines, "\n")); throw new RuntimeException("javac failed"); } } catch (InterruptedException e) { throw new RuntimeException(e.getMessage()); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return abs_paths(find_classes(build.toString())); }
From source file:net.sf.sahi.util.Utils.java
public static String executeCommand(String[] command) throws Exception { StringBuffer sb = new StringBuffer(); Process p = Runtime.getRuntime().exec(command); InputStream stdInput = p.getInputStream(); InputStream stdError = p.getErrorStream(); StringBuffer inBuffer = new StringBuffer(); StringBuffer errBuffer = new StringBuffer(); Thread inThread = new Thread(new StreamReader(stdInput, inBuffer)); inThread.start();// w ww. j a v a 2 s . c om Thread errThread = new Thread(new StreamReader(stdError, errBuffer)); errThread.start(); p.waitFor(); inThread.join(); errThread.join(); sb.append(inBuffer); sb.append(errBuffer); return sb.toString(); }
From source file:com.ms.commons.file.service.ImageUtil.java
public static String rotateImage(String originalImagePath, Double rotation) { // FIXME?Java? // JavaRuntime? // convert 1372771154717.jpg -virtual-pixel none +distort SRT '20' rotate_normal2.png String destImage = TEMP_IMAGE_PATH + System.currentTimeMillis() + ".png"; try {//www . j av a2s . c o m String command = null; command = "convert " + originalImagePath + " -virtual-pixel none +distort SRT '" + rotation + "' " + destImage; Process process = Runtime.getRuntime().exec(command); process.waitFor(); int exitValue = process.exitValue(); return exitValue == 0 ? destImage : StringUtils.EMPTY; } catch (IOException e1) { e1.printStackTrace(); return StringUtils.EMPTY; } catch (InterruptedException e) { e.printStackTrace(); return StringUtils.EMPTY; } // ConvertCmd convert = new ConvertCmd(); // IMOperation op = new IMOperation(); // op.addImage(originalImagePath); // op.addRawArgs(" -virtual-pixel none +distort SRT '" + rotation + "' "); // op.addImage(destImage); // try { // convert.run(op); // return destImage; // } catch (Exception e) { // e.printStackTrace(); // return StringUtils.EMPTY; // } }
From source file:io.sloeber.core.managers.Manager.java
private static void symlink(String something, File somewhere) throws IOException, InterruptedException { Process process = Runtime.getRuntime().exec( new String[] { "ln", "-s", something, somewhere.getAbsolutePath() }, //$NON-NLS-1$ //$NON-NLS-2$ null, somewhere.getParentFile()); process.waitFor(); }
From source file:com.orange.clara.cloud.servicedbdumper.task.boot.sequences.BootSequenceBinaries.java
@Override public void runSequence() throws BootSequenceException { String[] commands = { "/bin/chmod", "-R", "+x", binariesPath.getAbsolutePath() }; logger.debug("Running command: " + String.join(" ", commands) + " ..."); ProcessBuilder pb = new ProcessBuilder(commands); Process p = null; try {//from w ww .j a v a 2s.com p = pb.start(); p.waitFor(); } catch (IOException | InterruptedException e) { throw new BootSequenceException("Error when booting: " + e.getMessage(), e); } logger.debug("Finished Command: " + String.join(" ", commands) + "."); }
From source file:com.tascape.qa.th.Utils.java
public static void waitForProcess(final Process process, final long timeout) throws InterruptedException { Thread t = new Thread() { @Override//from ww w . j a v a2s .co m public void run() { try { Thread.sleep(timeout); } catch (InterruptedException ex) { LOG.warn(ex.getMessage()); } finally { if (process != null) { process.destroy(); } } } }; t.setDaemon(true); t.start(); if (process != null) { int exitValue = process.waitFor(); LOG.trace("process {} exits with {}", process, exitValue); } }
From source file:Breaker.VideoTool.java
private void Convert(File convertFile) { int OSX = 0, MS = 1; String[] HBLoc = { "./Resources/HandBrakeCLI", ".\\Resources\\HandBrakeCLI.exe" }; String OS = System.getProperty("os.name"); try {/* w w w .j av a2s .c om*/ Runtime RT = Runtime.getRuntime(); // Gets default path String Execute = GetStringByOS(OS, HBLoc); Execute += " -i " + convertFile.getPath(); String newFileName = convertFile.getName(); if (BreakView.cleanFileName) { newFileName = CleanName(newFileName); } Execute += " -o " + BreakView.Converted + "/" + newFileName; if (BreakView.Preset != null) Execute += " --preset=\"" + BreakView.Preset + "\""; BV.SetWarningText(Execute); Process PC = RT.exec("ls"); PC.waitFor(); BufferedReader reader = new BufferedReader(new InputStreamReader(PC.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { System.out.println(line); } } catch (Exception e) { e.printStackTrace(); } }
From source file:FileUtil.java
/** * Runs a simple command in given directory. * The environment is inherited from the parent process (e.g. the * one in which this Java VM runs)./*from ww w .j a va2s . c o m*/ * * @return Standard output from the command. * @param command The command to run * @param directory The working directory to run the command in * @throws IOException If the command failed * @throws InterruptedException If the command was halted */ public static String runSimpleCommand(String command, String directory) throws IOException, InterruptedException { StringBuffer result = new StringBuffer(); System.out.println("Running simple command " + command + " in " + directory); Process process = Runtime.getRuntime().exec(command, null, new File(directory)); BufferedReader stdout = null; BufferedReader stderr = null; try { stdout = new BufferedReader(new InputStreamReader(process.getInputStream())); stderr = new BufferedReader(new InputStreamReader(process.getErrorStream())); String line; while ((line = stdout.readLine()) != null) { result.append(line + "\n"); } StringBuffer error = new StringBuffer(); while ((line = stderr.readLine()) != null) { error.append(line + "\n"); } if (error.length() > 0) { System.out.println("Command failed, error stream is: " + error); } process.waitFor(); } finally { // we must close all by exec(..) opened streams: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4784692 process.getInputStream().close(); if (stdout != null) stdout.close(); if (stderr != null) stderr.close(); } return result.toString(); }