List of usage examples for java.lang ProcessBuilder command
List command
To view the source code for java.lang ProcessBuilder command.
Click Source Link
From source file:com.google.dart.tools.debug.core.configs.DartServerLaunchConfigurationDelegate.java
private String describe(ProcessBuilder processBuilder) { StringBuilder builder = new StringBuilder(); for (String arg : processBuilder.command()) { builder.append(arg);//from ww w . j a v a2 s.c o m builder.append(" "); } return builder.toString().trim(); }
From source file:org.testeditor.dsl.common.util.MavenExecutor.java
/** * Executes a maven build in a new jvm. The executable of the current jvm is * used to create a new jvm./* w w w .j av a2 s. c o m*/ * * @param parameters * for maven (separated by spaces, e.g. "clean integration-test" * to execute the given goals) * @param pathtoPom * path to the folder where the pom.xml is located. * @param testParam * pvm parameter to identify the test case to be executed. * @param monitor * Progress monitor to handle cancel events. * @return the result interpreted as {@link IStatus}. * @throws IOException * on failure */ public int executeInNewJvm(String parameters, String pathToPom, String testParam, IProgressMonitor monitor, OutputStream outputStream) throws IOException { List<String> command = createMavenExecCommand(parameters, testParam); ProcessBuilder processBuilder = new ProcessBuilder(); processBuilder.directory(new File(pathToPom)); logger.info("Executing maven in folder='{}'.", pathToPom); logger.info("Executing maven in new jvm with command='{}'.", command); processBuilder.command(command); Process process = processBuilder.start(); PrintStream out = new PrintStream(outputStream); OutputStreamCopyUtil outputCopyThread = new OutputStreamCopyUtil(process.getInputStream(), out); OutputStreamCopyUtil errorCopyThread = new OutputStreamCopyUtil(process.getErrorStream(), out); outputCopyThread.start(); errorCopyThread.start(); try { while (!process.waitFor(100, TimeUnit.MILLISECONDS)) { if (monitor.isCanceled()) { process.destroy(); out.println("Operation cancelled."); return IStatus.CANCEL; } } return process.exitValue() == 0 ? IStatus.OK : IStatus.CANCEL; } catch (InterruptedException e) { logger.error("Caught exception.", e); return IStatus.ERROR; } }
From source file:org.opencb.cellbase.mongodb.loader.MongoDBCellBaseLoader.java
protected boolean runCreateIndexProcess(Path indexFilePath) throws IOException, InterruptedException { List<String> args = new ArrayList<>(); args.add("mongo"); args.add("--host"); args.add(cellBaseConfiguration.getDatabase().getHost()); if (cellBaseConfiguration.getDatabase().getUser() != null && !cellBaseConfiguration.getDatabase().getUser().equals("")) { args.addAll(Arrays.asList("-u", cellBaseConfiguration.getDatabase().getUser(), "-p", cellBaseConfiguration.getDatabase().getPassword())); }//from w ww .j a v a2 s . c o m if (cellBaseConfiguration != null && cellBaseConfiguration.getDatabase().getOptions().get("authenticationDatabase") != null) { args.add("--authenticationDatabase"); args.add(cellBaseConfiguration.getDatabase().getOptions().get("authenticationDatabase")); logger.debug("MongoDB 'authenticationDatabase' database parameter set to '{}'", cellBaseConfiguration.getDatabase().getOptions().get("authenticationDatabase")); } args.add(database); args.add(indexFilePath.toString()); ProcessBuilder processBuilder = new ProcessBuilder(args); logger.debug("Executing command: '{}'", StringUtils.join(processBuilder.command(), " ")); // processBuilder.redirectErrorStream(true); // if (logFilePath != null) { // processBuilder.redirectOutput(ProcessBuilder.Redirect.appendTo(new File(logFilePath))); // } Process process = processBuilder.start(); process.waitFor(); // Check process output boolean executedWithoutErrors = true; int genomeInfoExitValue = process.exitValue(); if (genomeInfoExitValue != 0) { logger.warn("Error executing {}, error code: {}", indexFilePath, genomeInfoExitValue); executedWithoutErrors = false; } return executedWithoutErrors; }
From source file:plugins.GerritTriggerTest.java
private Process logProcessBuilderIssues(ProcessBuilder pb, String commandName) throws InterruptedException, IOException { String dir = ""; if (pb.directory() != null) { dir = pb.directory().getAbsolutePath(); }/*from w w w .ja v a 2s.c o m*/ LOGGER.info("Running : " + pb.command() + " => directory: " + dir); Process processToRun = pb.start(); int result = processToRun.waitFor(); if (result != 0) { StringWriter writer = new StringWriter(); IOUtils.copy(processToRun.getErrorStream(), writer); LOGGER.severe("Issue occurred during command \"" + commandName + "\":\n" + writer.toString()); writer.close(); } return processToRun; }
From source file:org.cryptomator.frontend.webdav.mount.WindowsWebDavMounter.java
private void addProxyOverrides(URI uri) throws IOException, CommandFailedException { try {//from ww w . j av a 2 s . co m // get existing value for ProxyOverride key from reqistry: ProcessBuilder query = new ProcessBuilder("reg", "query", "\"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\"", "/v", "ProxyOverride"); Process queryCmd = query.start(); String queryStdOut = IOUtils.toString(queryCmd.getInputStream(), StandardCharsets.UTF_8); int queryResult = queryCmd.waitFor(); // determine new value for ProxyOverride key: Set<String> overrides = new HashSet<>(); Matcher matcher = REG_QUERY_PROXY_OVERRIDES_PATTERN.matcher(queryStdOut); if (queryResult == 0 && matcher.find()) { String[] existingOverrides = StringUtils.split(matcher.group(1), ';'); overrides.addAll(Arrays.asList(existingOverrides)); } overrides.removeIf(s -> s.startsWith(uri.getHost() + ":")); overrides.add("<local>"); overrides.add(uri.getHost()); overrides.add(uri.getHost() + ":" + uri.getPort()); // set new value: String overridesStr = StringUtils.join(overrides, ';'); ProcessBuilder add = new ProcessBuilder("reg", "add", "\"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\"", "/v", "ProxyOverride", "/d", "\"" + overridesStr + "\"", "/f"); LOG.debug("Invoking command: " + StringUtils.join(add.command(), ' ')); Process addCmd = add.start(); int addResult = addCmd.waitFor(); if (addResult != 0) { String addStdErr = IOUtils.toString(addCmd.getErrorStream(), StandardCharsets.UTF_8); throw new CommandFailedException(addStdErr); } } catch (IOException | CommandFailedException e) { LOG.info("Failed to add proxy overrides", e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); InterruptedIOException ioException = new InterruptedIOException(); ioException.initCause(e); throw ioException; } }
From source file:org.sipfoundry.sipxconfig.admin.BackupPlan.java
private boolean perform(File workingDir, File binDir) throws IOException, InterruptedException { ProcessBuilder pb = new ProcessBuilder(binDir.getPath() + File.separator + m_backupScript, "-n"); if (!isVoicemail()) { // Configuration only. pb.command().add("-c"); } else if (!isConfigs()) { // Voicemail only. pb.command().add("-v"); }//from w ww .j av a 2 s.c o m Process process = pb.directory(workingDir).start(); int code = process.waitFor(); if (code != 0) { String errorMsg = String.format("Backup operation failed. Exit code: %d", code); LOG.error(errorMsg); return false; } return true; }
From source file:org.apache.kudu.client.MiniKdc.java
private Process startProcessWithKrbEnv(String... argv) throws IOException { ProcessBuilder procBuilder = new ProcessBuilder(argv); procBuilder.environment().putAll(getEnvVars()); LOG.debug("executing '{}', env: '{}'", Joiner.on(" ").join(procBuilder.command()), Joiner.on(", ").withKeyValueSeparator("=").join(procBuilder.environment())); return procBuilder.redirectErrorStream(true).start(); }
From source file:com.baifendian.swordfish.execserver.job.ProcessJob.java
/** * ?//from w w w. ja v a2 s.c om * * @param processBuilder */ private void printCommand(ProcessBuilder processBuilder) { String cmdStr; try { cmdStr = ProcessUtil.genCmdStr(processBuilder.command()); logger.info("job run command:\n{}", cmdStr); } catch (IOException e) { logger.error(e.getMessage(), e); } }
From source file:functionaltests.scilab.AbstractScilabTest.java
public void run() throws Throwable { init();/*ww w .j a va2s . co m*/ ProcessBuilder pb = new ProcessBuilder(); pb.directory(sci_tb_home); pb.redirectErrorStream(true); if (System.getProperty("scilab.bin.path") != null) { pb.command(System.getProperty("scilab.bin.path"), "-nw", "-f", (new File(test_home + fs + "PrepareTest.sci")).getCanonicalPath()); } else { pb.command("scilab", "-nw", "-f", (new File(test_home + fs + "PrepareTest.sci")).getCanonicalPath()); } System.out.println("Running command : " + pb.command()); File okFile = new File(sci_tb_home + fs + "ok.tst"); File koFile = new File(sci_tb_home + fs + "ko.tst"); if (okFile.exists()) { okFile.delete(); } if (koFile.exists()) { koFile.delete(); } Process p = pb.start(); IOTools.LoggingThread lt1 = new IOTools.LoggingThread(p.getInputStream(), "[AbstractScilabTest]", System.out); Thread t1 = new Thread(lt1, "AbstractScilabTest"); t1.setDaemon(true); t1.start(); p.waitFor(); assertTrue("Prepare Scilab Test passed", okFile.exists()); }
From source file:org.jvnet.hudson.update_center.Main.java
/** * Creates a symlink.// w w w .jav a 2s. c o m */ private void ln(String from, File to) throws InterruptedException, IOException { to.getParentFile().mkdirs(); ProcessBuilder pb = new ProcessBuilder(); pb.command("ln", "-sf", from, to.getAbsolutePath()); if (pb.start().waitFor() != 0) throw new IOException("ln failed"); }