List of usage examples for java.lang ProcessBuilder directory
File directory
To view the source code for java.lang ProcessBuilder directory.
Click Source Link
From source file:com.web.searchlocal.flashpaper.thread.Covnert2SwfTask.java
/** * //from w w w .j a v a 2 s . co m */ public void excute() { String tmpOutFile = outFile.getPath().concat(File.separator) .concat(inFile.getName().replaceAll("[.]{1}.*$", ".swf")); List<String> commandArray = new ArrayList<String>(); commandArray.add(defaultCommand); commandArray.add(inFile.getPath()); commandArray.add("-o"); commandArray.add(tmpOutFile); ProcessBuilder pbObj = new ProcessBuilder(); pbObj.command(commandArray); pbObj.directory(outFile); pbObj.redirectErrorStream(true); try { Process proObj = pbObj.start(); final InputStream ins = proObj.getInputStream(); final ByteBuffer byteBuffer = ByteBuffer.allocate(1024); Thread th = new Thread() { public void run() { ReadableByteChannel rbcObj = Channels.newChannel(ins); try { while (rbcObj.read(byteBuffer) != -1) { byteBuffer.flip(); logger.info(java.nio.charset.Charset.defaultCharset().decode(byteBuffer)); byteBuffer.clear(); } } catch (IOException e) { logger.error(e); } } }; th.setDaemon(true); th.start(); try { proObj.waitFor(); logger.error("??." + tmpOutFile); } catch (InterruptedException e) { logger.error(e); } } catch (IOException e) { logger.error(e); } }
From source file:org.kie.workbench.common.services.backend.compiler.offprocess.impl.CompilerIPCCoordinatorImpl.java
private void invokeServerBuild(String mavenRepo, String projectPath, String uuid, String classpath, String alternateSettingsAbsPath, String queueName) throws Exception { String[] commandArrayServer = { javaBin, "-cp", getClasspathIncludedCurrentModuleDep(mavenRepo, classpath), "-Dorg.uberfire.nio.git.daemon.enabled=false", "-Dorg.uberfire.nio.ssh.daemon.enabled=false", ServerIPCImpl.class.getCanonicalName(), uuid, projectPath, mavenRepo, alternateSettingsAbsPath, queueName };/*from w w w .j a v a2s .c o m*/ if (logger.isDebugEnabled()) { logger.debug( "************************** \n Invoking server in a separate process with args: \n{} \n{} \n{} \n{} \n{} \n{} \n{} \n{} \n**************************", commandArrayServer); } ProcessBuilder serverPb = new ProcessBuilder(commandArrayServer); serverPb.directory(new File(projectPath)); serverPb.redirectErrorStream(true); serverPb.inheritIO(); writeStdOut(serverPb); }
From source file:org.sonar.process.monitor.JavaProcessLauncher.java
private ProcessBuilder create(JavaCommand javaCommand) { List<String> commands = new ArrayList<>(); commands.add(buildJavaPath());// www. j a va 2 s .c o m commands.addAll(javaCommand.getJavaOptions()); // TODO warning - does it work if temp dir contains a whitespace ? commands.add(String.format("-Djava.io.tmpdir=%s", tempDir.getAbsolutePath())); commands.add(getJmxAgentCommand()); commands.addAll(buildClasspath(javaCommand)); commands.add(javaCommand.getClassName()); commands.add(buildPropertiesFile(javaCommand).getAbsolutePath()); ProcessBuilder processBuilder = new ProcessBuilder(); processBuilder.command(commands); processBuilder.directory(javaCommand.getWorkDir()); processBuilder.environment().putAll(javaCommand.getEnvVariables()); processBuilder.redirectErrorStream(true); return processBuilder; }
From source file:io.jmnarloch.cd.go.plugin.sbt.SbtTaskExecutor.java
/** * Builds the SBT process to be executed * * @param environment the build environment * @param config the build configuration * @return the SBT process// www . j av a 2 s . c o m */ private ProcessBuilder buildSbtProcess(ExecutionContext environment, ExecutionConfiguration config) { final Map<String, String> env = environment.getEnvironmentVariables(); final List<String> command = parse(config, env); logger.debug("Executing command: " + command); final ProcessBuilder builder = new ProcessBuilder(command); builder.environment().putAll(env); builder.directory(new File(environment.getWorkingDirectory())); return builder; }
From source file:com.l2jfree.sql.L2DataSourceMySQL.java
@Override public void backup() { final String databaseName = getComboPooledDataSource().getJdbcUrl().replaceAll("^.*/", ""); _log.info("DatabaseBackupManager: backing up `" + databaseName + "`..."); final Process run; try {//from w w w .j a v a 2 s . c o m final ArrayList<String> commands = new ArrayList<String>(); commands.add("mysqldump"); commands.add(" --user=" + getComboPooledDataSource().getUser()); // The MySQL user name to use when connecting to the server commands.add(" --password=" + getComboPooledDataSource().getPassword()); // The password to use when connecting to the server commands.add("--compact"); // Produce more compact output. commands.add("--complete-insert"); // Use complete INSERT statements that include column names commands.add("--default-character-set=utf8"); // Use charset_name as the default character set commands.add("--extended-insert"); // Use multiple-row INSERT syntax that include several VALUES lists commands.add("--lock-tables"); // Lock all tables before dumping them commands.add("--quick"); // Retrieve rows for a table from the server a row at a time commands.add("--skip-triggers"); // Do not dump triggers commands.add(databaseName); // db_name final ProcessBuilder pb = new ProcessBuilder(commands); pb.directory(new File(".")); run = pb.start(); } catch (Exception e) { _log.warn("DatabaseBackupManager: Could not execute mysqldump!", e); return; } writeBackup(databaseName, run); }
From source file:no.antares.clutil.hitman.process.ProcessControlProcessBuilder.java
/** @see no.antares.clutil.hitman.process.ProcessControl#start() */ @Override// w w w . j ava 2s . co m public void start() { logger.info("start() " + fullCall); synchronized (this) { if (process != null) return; try { ProcessBuilder builder = new ProcessBuilder(programAndArguments); if (this.workingDir != null) builder.directory(this.workingDir); process = builder.start(); procOut = new ProcessOut(process); procOut.start(); } catch (Throwable e) { logger.fatal("start(): " + fullCall, e); throw new RuntimeException("Error starting process: " + fullCall, e); } } logger.info("start() process started: " + (process != null)); }
From source file:es.amplia.research.maven.protodocbook.cmd.Factory.java
private void execute(File directory, String... cmd) throws Exception { ProcessBuilder pb = new ProcessBuilder(cmd); Map<String, String> env = pb.environment(); pb.directory(directory); pb.redirectErrorStream(true);// w w w . j ava2 s.c om Process p = pb.start(); p.waitFor(); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; while ((line = br.readLine()) != null) { if (this.log.isInfoEnabled()) this.log.info(line); } }
From source file:org.apache.geode.test.junit.rules.gfsh.GfshRule.java
protected ProcessBuilder toProcessBuilder(GfshScript gfshScript, Path gfshPath, File workingDir) { List<String> commandsToExecute = new ArrayList<>(); commandsToExecute.add(gfshPath.toAbsolutePath().toString()); for (String command : gfshScript.getCommands()) { commandsToExecute.add("-e " + command); }//from w w w.ja v a 2 s . c o m ProcessBuilder processBuilder = new ProcessBuilder(commandsToExecute); processBuilder.directory(workingDir); List<String> extendedClasspath = gfshScript.getExtendedClasspath(); if (!extendedClasspath.isEmpty()) { Map<String, String> environmentMap = processBuilder.environment(); String classpathKey = "CLASSPATH"; String existingJavaArgs = environmentMap.get(classpathKey); String specified = String.join(PATH_SEPARATOR, extendedClasspath); String newValue = String.format("%s%s", existingJavaArgs == null ? "" : existingJavaArgs + ":", specified); environmentMap.put(classpathKey, newValue); } return processBuilder; }
From source file:org.obiba.rserver.service.RServerService.java
private ProcessBuilder buildRProcess() { List<String> args = getArguments(); log.info("Starting R server: {}", StringUtils.collectionToDelimitedString(args, " ")); ProcessBuilder pb = new ProcessBuilder(args); pb.directory(getWorkingDirectory()); pb.redirectErrorStream(true);//from ww w . j a v a 2s. c om pb.redirectOutput(ProcessBuilder.Redirect.appendTo(getRserveLogFile())); return pb; }
From source file:org.apache.jackrabbit.webdav.simple.LitmusTest.java
public void testLitmus() throws Exception { File dir = new File("target", "litmus"); String litmus = System.getProperty("litmus", "litmus"); if (Boolean.getBoolean("jackrabbit.test.integration") && isLitmusAvailable(litmus)) { final Repository repository = JcrUtils .getRepository("jcr-jackrabbit://" + Text.escapePath(dir.getCanonicalPath())); Session session = repository.login(); // for the TransientRepository try {//w ww.ja v a 2s. c om SocketConnector connector = new SocketConnector(); connector.setHost("localhost"); connector.setPort(Integer.getInteger("litmus.port", 0)); Server server = new Server(); server.addConnector(connector); ServletHolder holder = new ServletHolder(new SimpleWebdavServlet() { @Override public Repository getRepository() { return repository; } }); holder.setInitParameter("resource-config", "/config.xml"); Context context = new Context(server, "/"); context.setResourceBase("src/test/resources"); context.addServlet(holder, "/*"); server.addHandler(context); server.start(); try { int port = connector.getLocalPort(); String url = "http://localhost:" + port + "/default"; ProcessBuilder builder = new ProcessBuilder(litmus, url, "admin", "admin"); builder.directory(dir); builder.redirectErrorStream(); assertLitmus(builder, "basic", 0); assertLitmus(builder, "http", 0); assertLitmus(builder, "props", 0); // FIXME: JCR-2637: WebDAV shallow copy test failure assertLitmus(builder, "copymove", 1); // FIXME: JCR-2638: Litmus locks test failures assertLitmus(builder, "locks", 1); } finally { server.stop(); } } finally { session.logout(); } } }