List of usage examples for java.lang Process waitFor
public abstract int waitFor() throws InterruptedException;
From source file:cu.uci.uengine.utils.FileUtils.java
public static boolean dos2unixFileFixer(String filePath) throws IOException, InterruptedException { // bash es muy sensible a los cambios de linea \r\n de Windows. Para // prevenir que esto cause Runtime Errors, es necesario convertirlos a // un sistema comprensible por ubuntu: \n normal en linux. El comando // dos2unix hace esto. // se lo dejamos a todos los codigos para evitar que algun otro lenguaje // tambien padezca de esto Properties langProps = new Properties(); langProps.load(ClassLoader.getSystemResourceAsStream("uengine.properties")); String dos2unixPath = langProps.getProperty("dos2unix.path"); ProcessBuilder pb = new ProcessBuilder(dos2unixPath, filePath); Process process = pb.start(); process.waitFor(); return process.exitValue() == 0; }
From source file:design.process.ProcessUtil.java
/***/ public static Process executeProcess(final File workDir, final String... termArray) throws IOException, InterruptedException { final List<String> termList = Arrays.asList(termArray); final ProcessBuilder builder = new ProcessBuilder(termList); final Process process = builder.directory(workDir).start(); process.waitFor(); return process; }
From source file:hu.bme.mit.trainbenchmark.sql.process.MySqlProcess.java
public static void run(final String command[]) throws IOException, InterruptedException { final ProcessBuilder pb = new ProcessBuilder(command); final Process p = pb.start(); p.waitFor(); final String stdOut = getInputAsString(p.getInputStream()); final String stdErr = getInputAsString(p.getErrorStream()); // System.out.println(stdOut); // System.out.println(stdErr); }
From source file:Main.java
public static boolean isOnline() { Runtime runtime = Runtime.getRuntime(); try {//from w w w .j a v a 2s . c o m Process ipProcess = runtime.exec("/system/bin/ping -c 1 8.8.8.8"); int exitValue = ipProcess.waitFor(); return (exitValue == 0); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static Boolean isOnline() { try {//from ww w .j av a 2 s . c o m Process p1 = java.lang.Runtime.getRuntime().exec("ping -n 1 www.google.com"); int returnVal = p1.waitFor(); boolean reachable = (returnVal == 0); return reachable; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; }
From source file:Main.java
public static void setConfigSpec(String viewTag, String configSpecFilePath) { try {/* w w w. j av a 2s . c om*/ Process pr = Runtime.getRuntime().exec("cleartool setcs -tag " + viewTag + " " + configSpecFilePath); pr.waitFor(); pr.destroy(); } catch (Exception e) { throw new RuntimeException("cleartool setcs error!", e); } }
From source file:io.bitgrillr.gocddockerexecplugin.SystemHelper.java
static String getSystemUid() throws IOException, InterruptedException { Process id = Runtime.getRuntime().exec(new String[] { "bash", "-c", "echo \"$(id -u):$(id -g)\"" }); id.waitFor(); return StringUtils.chomp(IOUtils.toString(id.getInputStream(), StandardCharsets.UTF_8)); }
From source file:com.alibaba.jstorm.utils.SystemOperation.java
public static String exec(String cmd) throws IOException { LOG.debug("Shell cmd: " + cmd); Process process = new ProcessBuilder(new String[] { "/bin/bash", "-c", cmd }).start(); try {//from ww w . j av a 2 s.co m process.waitFor(); String output = IOUtils.toString(process.getInputStream()); String errorOutput = IOUtils.toString(process.getErrorStream()); LOG.debug("Shell Output: " + output); if (errorOutput.length() != 0) { LOG.error("Shell Error Output: " + errorOutput); throw new IOException(errorOutput); } return output; } catch (InterruptedException ie) { throw new IOException(ie.toString()); } }
From source file:Main.java
private static boolean waitForProcess(Process p) { boolean isSuccess = false; int returnCode; try {/*from w w w . j av a2 s .c om*/ returnCode = p.waitFor(); switch (returnCode) { case 0: isSuccess = true; break; case 1: break; default: break; } } catch (InterruptedException e) { e.printStackTrace(); } return isSuccess; }
From source file:Main.java
/** * Try to delete directory in a fast way. */// w ww . j a v a 2s. com public static void deleteDirectoryQuickly(File dir) throws IOException { if (!dir.exists()) { return; } final File to = new File(dir.getAbsolutePath() + System.currentTimeMillis()); dir.renameTo(to); if (!dir.exists()) { // rebuild dir.mkdirs(); } // try to run "rm -r" to remove the whole directory if (to.exists()) { String deleteCmd = "rm -r " + to; Runtime runtime = Runtime.getRuntime(); try { Process process = runtime.exec(deleteCmd); process.waitFor(); } catch (IOException e) { } catch (InterruptedException e) { e.printStackTrace(); } } if (!to.exists()) { return; } deleteDirectoryRecursively(to); if (to.exists()) { to.delete(); } }