List of usage examples for java.lang Process exitValue
public abstract int exitValue();
From source file:eu.cloud4soa.c4sgitservice.utils.Util.java
public static synchronized int replaceBlockWithSedForAuthorizedKeys(String filename, String pubkeyid) { int retvalue = 1; //1=ERROR 0=OK try {//from w ww .j a v a2s . co m String sedblock = createSedBlockForAuthorizedKeys(pubkeyid); System.out.println(" sed -e " + sedblock + " " + filename); String[] command = new String[] { "sed", "-i", // -i is for replace // -e is used for piping sedblock, filename }; System.out.println(command.toString()); Process child = Runtime.getRuntime().exec(command); child.waitFor(); //Get the input stream and read from it InputStream in = child.getInputStream(); int c; while ((c = in.read()) != -1) { System.out.print((char) c); } in.close(); retvalue = child.exitValue(); System.out.println("Replace file returned: " + retvalue); } catch (Exception ex) { ex.printStackTrace(); } return retvalue; }
From source file:eu.cloud4soa.c4sgitservice.utils.Util.java
public static synchronized int replaceBlockWithSedForProxyGit(String filename, String tag) { int retvalue = 1; //1=ERROR 0=OK try {//from w w w .j a v a 2 s . c o m String sedblock = createSedBlockForProxyGit(tag); System.out.println(" sed -e " + sedblock + " " + filename); String[] command = new String[] { "sed", "-i", // -i is for replace // -e is used for piping sedblock, filename }; System.out.println(command.toString()); Process child = Runtime.getRuntime().exec(command); child.waitFor(); //Get the input stream and read from it InputStream in = child.getInputStream(); int c; while ((c = in.read()) != -1) { System.out.print((char) c); } in.close(); retvalue = child.exitValue(); System.out.println("Replace file returned: " + retvalue); } catch (Exception ex) { ex.printStackTrace(); } return retvalue; }
From source file:org.renjin.primitives.System.java
@Internal("system") public static SEXP system(@Current Context context, String command, int flag, SEXP stdin, SEXP stdout, SEXP stderr) throws IOException, InterruptedException { boolean invisible = (flag >= 20 && flag < 29); boolean minimized = (flag >= 10 && flag < 19); List<String> args = parseArgs(command); ProcessBuilder builder = new ProcessBuilder(args); FileObject workingDir = context.getSession().getWorkingDirectory(); if (workingDir instanceof LocalFile) { File localDir = new File(workingDir.getURL().getFile()); builder.directory(localDir);//from www . ja v a2s.com } Process process = builder.start(); process.waitFor(); int exitValue = process.exitValue(); return new IntArrayVector(exitValue); }
From source file:Main.java
public static int execRootCmdSilent(String cmd) { try {/*from w w w . jav a 2 s. co m*/ Process p = Runtime.getRuntime().exec("su "); Object obj = p.getOutputStream(); DataOutputStream dOutStream = new DataOutputStream((OutputStream) obj); String str = String.valueOf(cmd); obj = str + "\n"; dOutStream.writeBytes((String) obj); dOutStream.flush(); dOutStream.writeBytes("exit\n"); dOutStream.flush(); p.waitFor(); int result = p.exitValue(); return (Integer) result; } catch (Exception e) { e.printStackTrace(); return -1; } }
From source file:edu.clemson.cs.nestbed.server.util.UsbPowerControl.java
private static void setPowerState(int bus, int device, int port, int state) { ProcessBuilder processBuilder; Process process; int exitValue; try {//from ww w. j a v a2 s. c o m //processBuilder = new ProcessBuilder(SET_DEV_POWER, processBuilder = new ProcessBuilder("/usr/bin/sudo", SET_DEV_POWER, "-b", Integer.toString(bus), "-d", Integer.toString(device), "-P", Integer.toString(port), "-p", Integer.toString(state)); process = processBuilder.start(); process.waitFor(); exitValue = process.exitValue(); if (exitValue == 0) { log.debug("Set power state successfully"); } else { log.error("Unable to set power state"); } } catch (InterruptedException ex) { log.error("Process interrupted", ex); } catch (IOException ex) { log.error("I/O Exception occured while reading device info", ex); } }
From source file:org.apache.storm.daemon.supervisor.ClientSupervisorUtils.java
public static int processLauncherAndWait(Map<String, Object> conf, String user, List<String> args, final Map<String, String> environment, final String logPreFix) throws IOException { int ret = 0;// ww w .j a v a2s . c om Process process = processLauncher(conf, user, null, args, environment, logPreFix, null, null); if (StringUtils.isNotBlank(logPreFix)) Utils.readAndLogStream(logPreFix, process.getInputStream()); try { process.waitFor(); } catch (InterruptedException e) { LOG.info("{} interrupted.", logPreFix); } ret = process.exitValue(); return ret; }
From source file:ml.shifu.shifu.executor.ProcessManager.java
public static int runShellProcess(String currentDir, String[] args) throws IOException { ProcessBuilder processBuilder = new ProcessBuilder(args); processBuilder.directory(new File(currentDir)); processBuilder.redirectErrorStream(true); Process process = processBuilder.start(); LogThread logThread = new LogThread(process, process.getInputStream(), currentDir); logThread.start();/*from w w w. ja v a 2 s. c o m*/ try { process.waitFor(); } catch (InterruptedException e) { process.destroy(); } finally { logThread.setToQuit(true); } LOG.info("Under {} directory, finish run `{}`", currentDir, args); return process.exitValue(); }
From source file:org.kuali.student.git.utils.ExternalGitUtils.java
public static boolean updateRef(String externalGitCommand, Repository repo, String absoluteRefName, ObjectId objectId, boolean force, OutputStream redirectStream) throws IOException { List<String> commandOptions = new ArrayList<>(); commandOptions.add("branch"); if (force)//w w w . j a va 2s. co m commandOptions.add("-f"); commandOptions.add(absoluteRefName); commandOptions.add(objectId.getName()); try { Process p = runGitCommand(repo, true, commandOptions); waitFor(p, redirectStream); if (p.exitValue() == 0) return true; else return false; } catch (InterruptedException e) { } return false; }
From source file:org.schreibubi.JCombinationsTools.coordinatorPatch.CoordinatorPatch.java
private static void compile(String[] makecommand, boolean silent) throws IOException, InterruptedException, Exception { ProcessBuilder pb = new ProcessBuilder(makecommand); // Map< String, String > en = pb.environment(); /*//from w w w.j a v a2 s . c o m * for ( String string : en.keySet() ) { System.out.println( string + "=" + en.get( string ) ); } */ pb.redirectErrorStream(true); Process p = pb.start(); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); if (!silent) { String c; while ((c = br.readLine()) != null) { System.out.println(c); } } p.waitFor(); int retVal = p.exitValue(); if (retVal != 0) throw new Exception("Compilation failed!"); }
From source file:com.streamsets.datacollector.util.SystemProcessImpl.java
/** * Java 1.7 does not have Process.waitFor(timeout) *///from w ww . j av a 2 s . c o m private static boolean waitFor(Process process, long timeout, TimeUnit unit) { long startTime = System.nanoTime(); long rem = unit.toNanos(timeout); do { try { process.exitValue(); return true; } catch (IllegalThreadStateException ex) { if (rem > 0) ThreadUtil.sleep(Math.min(TimeUnit.NANOSECONDS.toMillis(rem) + 1, 100)); } rem = unit.toNanos(timeout) - (System.nanoTime() - startTime); } while (rem > 0); return false; }