List of usage examples for java.lang ProcessBuilder ProcessBuilder
public ProcessBuilder(String... command)
From source file:com.netflix.raigad.defaultimpl.ElasticSearchProcessManager.java
public void start(boolean join_ring) throws IOException { logger.info("Starting elasticsearch server"); List<String> command = Lists.newArrayList(); if (!"root".equals(System.getProperty("user.name"))) { command.add(SUDO_STRING);//from w w w . j av a 2 s . c o m command.add("-n"); command.add("-E"); } command.addAll(getStartCommand()); ProcessBuilder startEs = new ProcessBuilder(command); Map<String, String> env = startEs.environment(); env.put("DATA_DIR", config.getDataFileLocation()); startEs.directory(new File("/")); startEs.redirectErrorStream(true); Process starter = startEs.start(); logger.info("Starting Elasticsearch server ...."); try { sleeper.sleepQuietly(SCRIPT_EXECUTE_WAIT_TIME_MS); int code = starter.exitValue(); if (code == 0) logger.info("Elasticsearch server has been started"); else logger.error("Unable to start Elasticsearch server. Error code: {}", code); logProcessOutput(starter); } catch (Exception e) { logger.warn("Starting Elasticsearch has an error", e.getMessage()); } }
From source file:com.mewmew.fairy.v1.book.Xargs.java
public static void exec(Map<String, String> env, String cmd[], boolean redirectError, Output<String> output) throws IOException, InterruptedException { ProcessBuilder pb = new ProcessBuilder(cmd); if (env != null) { pb.environment().putAll(env);/*from w w w . j ava 2 s. co m*/ } if (redirectError) { pb.redirectErrorStream(true); } final Process p = pb.start(); if (!redirectError) { new Thread(new Runnable() { public void run() { try { LineIterator err = new LineIterator(new InputStreamReader(p.getErrorStream())); while (err.hasNext()) { err.next(); } } finally { } } }).start(); } LineIterator out = new LineIterator(new InputStreamReader(p.getInputStream())); while (out.hasNext()) { output.output(out.nextLine()); } int code = p.waitFor(); if (code != 0) { throw new RuntimeException(String.format("return != 0, code = %d", code)); } }
From source file:io.galeb.router.handlers.InfoHandler.java
private String getUptimeSO() { ProcessBuilder processBuilder = new ProcessBuilder("uptime"); processBuilder.redirectErrorStream(true); try {/*ww w. j a v a2s . c o m*/ Process process = processBuilder.start(); return IOUtils.toString(process.getInputStream(), "UTF-8").replace("\n", ""); } catch (Exception e) { logger.error(ExceptionUtils.getStackTrace(e)); return ""; } }
From source file:com.consol.citrus.admin.launcher.process.ExecuteCommand.java
public ProcessBuilder getProcessBuilder() { validateWorkingDirectory(workingDirectory); List<String> commands = new ArrayList<String>(); if (SystemUtils.IS_OS_UNIX) { commands.add(BASH);/*from w w w .j ava 2 s .co m*/ commands.add(BASH_OPTION_C); } else { commands.add(CMD); commands.add(CMD_OPTION_C); } commands.add(buildCommand(command)); ProcessBuilder pb = new ProcessBuilder(commands); pb.directory(workingDirectory); LOG.trace("Returning ProcessBuilder for command:" + commands); return pb; }
From source file:com.floreantpos.main.Main.java
public static void restart() throws IOException, InterruptedException, URISyntaxException { final String javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ // Properties properties = System.getProperties(); // Set<Object> keySet = properties.keySet(); // for (Object object : keySet) { // PosLog.debug(getClass(),object + ":"+properties.getProperty((String) object)); // }/*from w w w . j a va 2 s.c o m*/ String classPath = System.getProperty("java.class.path"); //$NON-NLS-1$ String mainClass = System.getProperty("sun.java.command"); //$NON-NLS-1$ /* Build command: java -jar application.jar */ final ArrayList<String> command = new ArrayList<String>(); command.add(javaBin); command.add("-cp"); //$NON-NLS-1$ command.add(classPath); command.add(mainClass); final ProcessBuilder builder = new ProcessBuilder(command); builder.start(); System.exit(0); }
From source file:com.hortonworks.registries.storage.tool.shell.ShellMigrationExecutor.java
@Override public void execute(Connection connection) throws SQLException { String scriptLocation = this.shellScriptResource.getLocationOnDisk(); try {/*w w w. ja va 2s . com*/ List<String> args = new ArrayList<String>(); args.add(scriptLocation); ProcessBuilder builder = new ProcessBuilder(args); builder.redirectErrorStream(true); Process process = builder.start(); Scanner in = new Scanner(process.getInputStream()); System.out.println(StringUtils.repeat("+", 200)); while (in.hasNextLine()) { System.out.println(in.nextLine()); } int returnCode = process.waitFor(); System.out.println(StringUtils.repeat("+", 200)); if (returnCode != 0) { throw new FlywayException("script exited with value : " + returnCode); } } catch (Exception e) { LOG.error(e.toString()); // Only if SQLException or FlywaySqlScriptException is thrown flyway will mark the migration as failed in the metadata table throw new SQLException(String.format("Failed to run script \"%s\", %s", scriptLocation, e.getMessage()), e); } }
From source file:com.mbrlabs.mundus.assets.FbxConv.java
public FbxConv(String fbxBinary) { this.fbxBinary = fbxBinary; if (SystemUtils.IS_OS_MAC) { os = Os.MAC;//from w w w . j av a 2 s .c o m } else if (SystemUtils.IS_OS_WINDOWS) { os = Os.WINDOWS; } else if (SystemUtils.IS_OS_LINUX) { os = Os.LINUX; } else { throw new OsNotSupported(); } pb = new ProcessBuilder(fbxBinary); }
From source file:fitnesse.testsystems.CommandRunner.java
public void asynchronousStart() throws IOException { ProcessBuilder processBuilder = new ProcessBuilder(command); processBuilder.environment().putAll(determineEnvironment()); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Starting process " + asList(command)); }// w w w .ja v a 2s . c o m process = processBuilder.start(); sendCommandStartedEvent(); redirectOutputs(process, executionLogListener); }
From source file:com.twosigma.beakerx.kernel.MagicKernelManager.java
private void initPythonProcess() throws NoSuchKernelException { //cleanup communication resources if already in use exit();//from ww w. j av a 2 s . c o m port = findFreePort(); pythonPort = findFreePort(); try { ProcessBuilder pb = new ProcessBuilder(getPy4jCommand()); pb.redirectError(ProcessBuilder.Redirect.INHERIT); pythonProcess = pb.start(); BufferedReader br = new BufferedReader(new InputStreamReader(pythonProcess.getInputStream())); while (!PY4J_INIT_MESSAGE.equals(br.readLine()) && pythonProcess.isAlive()) { //wait for python process to initialize properly } if (!pythonProcess.isAlive() && pythonProcess.exitValue() == NO_SUCH_KERNEL_CODE) { throw new NoSuchKernelException(kernelName); } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.netflix.dynomitemanager.defaultimpl.StorageProcessManager.java
public void start() throws IOException { logger.info(String.format("Starting Storage process")); List<String> command = Lists.newArrayList(); if (!"root".equals(System.getProperty("user.name"))) { command.add(SUDO_STRING);/* ww w. java 2 s .c o m*/ command.add("-n"); command.add("-E"); } command.addAll(getStartCommand()); ProcessBuilder startStorage = new ProcessBuilder(command); startStorage.directory(new File("/")); startStorage.redirectErrorStream(true); Process starter = startStorage.start(); try { sleeper.sleepQuietly(SCRIPT_EXECUTE_WAIT_TIME_MS); int code = starter.exitValue(); if (code == 0) { logger.info("Storage process has been started"); instanceState.setStorageProxyAlive(true); } else { logger.error("Unable to start Storage process. Error code: {}", code); } logProcessOutput(starter); } catch (Exception e) { logger.warn("Starting Storage process has an error", e); } }