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:org.openengsb.connector.script.internal.ScriptServiceImpl.java
private Process configureProcess(File dir, List<String> command) throws IOException { Process process;/*w w w .j a va 2 s . c o m*/ try { ProcessBuilder builder = new ProcessBuilder(command); process = builder.directory(dir).start(); } catch (IOException e) { /* Try again, relative to the karaf.data directory */ String newCmd = command.get(0); newCmd = new File(System.getProperty("karaf.data")).getAbsolutePath() + File.separator + newCmd; command.remove(0); command.add(0, newCmd); ProcessBuilder builder = new ProcessBuilder(command); process = builder.directory(dir).start(); } return process; }
From source file:com.framgia.android.emulator.EmulatorDetector.java
private boolean checkIp() { boolean ipDetected = false; if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.INTERNET) == PackageManager.PERMISSION_GRANTED) { String[] args = { "/system/bin/netcfg" }; StringBuilder stringBuilder = new StringBuilder(); try {// ww w . ja v a 2 s . c o m ProcessBuilder builder = new ProcessBuilder(args); builder.directory(new File("/system/bin/")); builder.redirectErrorStream(true); Process process = builder.start(); InputStream in = process.getInputStream(); byte[] re = new byte[1024]; while (in.read(re) != -1) { stringBuilder.append(new String(re)); } in.close(); } catch (Exception ex) { // empty catch } String netData = stringBuilder.toString(); log("netcfg data -> " + netData); if (!TextUtils.isEmpty(netData)) { String[] array = netData.split("\n"); for (String lan : array) { if ((lan.contains("wlan0") || lan.contains("tunl0") || lan.contains("eth0")) && lan.contains(IP)) { ipDetected = true; log("Check IP is detected"); break; } } } } return ipDetected; }
From source file:org.craftercms.studio.impl.v1.deployment.EnvironmentStoreGitBranchDeployer.java
private void createPatch(Repository repository, String site, String path) { StringBuffer output = new StringBuffer(); String tempPath = System.getProperty("java.io.tmpdir"); if (tempPath == null) { tempPath = "temp"; }//from w ww . j ava 2 s. c om Path patchPath = Paths.get(tempPath, "patch" + site + ".bin"); String gitPath = getGitPath(path); Process p = null; File file = patchPath.toAbsolutePath().normalize().toFile(); try { ProcessBuilder pb = new ProcessBuilder(); pb.command("git", "diff", "--binary", environment, "master", "--", gitPath); pb.redirectOutput(file); pb.directory(repository.getDirectory().getParentFile()); p = pb.start(); p.waitFor(); } catch (Exception e) { logger.error("Error while creating patch for site: " + site + " path: " + path, e); } }
From source file:org.pepstock.jem.junit.init.submitters.AbstractSubmitter.java
/** * //from ww w . jav a 2 s. com * @param command * @param args * @return * @throws NodeMessageException * @throws IOException * @throws InterruptedException */ int launch(String command, String[] args) throws NodeMessageException, IOException, InterruptedException { String osCommand = null; if (SystemUtils.IS_OS_WINDOWS) { osCommand = command + ".cmd"; } else { osCommand = command + ".sh"; } Process process = null; try { File logFile = File.createTempFile("junit", "log"); String redirect = "> " + FilenameUtils.normalize(logFile.getAbsolutePath(), true) + " 2>&1"; StringBuilder sb = new StringBuilder(osCommand); for (String arg : args) { sb.append(" ").append(arg); } System.err.println(sb.toString()); sb.append(" ").append(redirect); // create a process builder ProcessBuilder builder = new ProcessBuilder(); Shell shell = CurrentPlatform.getInstance().getShell(); builder.command(shell.getName(), shell.getParameters(), sb.toString()); // set directory where execute process builder.directory(new File(System.getenv("JEM_HOME") + "/bin")); // load variable environment from a temporary maps that you can use // inside of configure method. Map<String, String> env = System.getenv(); Map<String, String> map = builder.environment(); for (Map.Entry<String, String> e : env.entrySet()) { map.put(e.getKey(), e.getValue()); } // start process and save instance process = builder.start(); // wait for end of job execution int rc = process.waitFor(); FileInputStream fis = new FileInputStream(logFile); IOUtils.copy(fis, System.out); IOUtils.closeQuietly(fis); logFile.delete(); return rc; } finally { if (process != null) { process.destroy(); } } }
From source file:interactivespaces.activity.binary.BaseNativeActivityRunner.java
/** * Attempt the run./*from w ww . j a v a 2 s. com*/ * * @return the process that was created */ private Process attemptRun() { try { ProcessBuilder builder = new ProcessBuilder(commands); builder.directory(executableFolder); spaceEnvironment.getLog().info( String.format("Starting up native code in folder %s", executableFolder.getAbsolutePath())); return builder.start(); } catch (Exception e) { throw new InteractiveSpacesException("Can't start up activity " + appName, e); } }
From source file:com.ecofactor.qa.automation.platform.ops.impl.IOSOperations.java
/** * Start Appium server./*from ww w .j a va 2 s. c om*/ * @see com.ecofactor.qa.automation.mobile.ops.impl.AbstractMobileOperations#startAppiumServer() */ @Override public void startAppiumServer() { final String deviceId = getDeviceIdParam(); startProxyServer(deviceId); setLogString(LogSection.START, "Start appium server", true); try { final ProcessBuilder process = new ProcessBuilder( arrayToList("node", ".", "-U", deviceId, "-p", DEFAULT_PORT)); process.directory(new File("/Applications/Appium.app/Contents/Resources/node_modules/appium/")); process.redirectOutput(new File("outPut.txt")); process.redirectError(new File("error.txt")); startProcessBuilder(process); } catch (Exception e) { LOGGER.error("ERROR in starting Appium Server. Cause: ", e); } setLogString(LogSection.END, "Appium server started", true); }
From source file:org.dawnsci.commandserver.core.process.ProgressableProcess.java
protected void pkill(int pid, String dir) throws Exception { // Use pkill, seems to kill all of the tree more reliably ProcessBuilder pb = new ProcessBuilder(); // Can adjust env if needed: // Map<String, String> env = pb.environment(); pb.directory(new File(dir)); File log = new File(dir, "xia2_kill.txt"); pb.redirectErrorStream(true);//w w w .ja v a 2 s.c om pb.redirectOutput(Redirect.appendTo(log)); pb.command("bash", "-c", "pkill -9 -s " + pid); Process p = pb.start(); p.waitFor(); }
From source file:org.owasp.dependencycheck.analyzer.RubyBundleAuditAnalyzer.java
/** * Launch bundle-audit./*ww w.j a va2 s. c o m*/ * * @param folder directory that contains bundle audit * @return a handle to the process * @throws AnalysisException thrown when there is an issue launching bundle * audit */ private Process launchBundleAudit(File folder) throws AnalysisException { if (!folder.isDirectory()) { throw new AnalysisException( String.format("%s should have been a directory.", folder.getAbsolutePath())); } final List<String> args = new ArrayList<String>(); final String bundleAuditPath = Settings.getString(Settings.KEYS.ANALYZER_BUNDLE_AUDIT_PATH); args.add(null == bundleAuditPath ? "bundle-audit" : bundleAuditPath); args.add("check"); args.add("--verbose"); final ProcessBuilder builder = new ProcessBuilder(args); builder.directory(folder); try { LOGGER.info("Launching: " + args + " from " + folder); return builder.start(); } catch (IOException ioe) { throw new AnalysisException("bundle-audit failure", ioe); } }
From source file:de.tudarmstadt.ukp.dkpro.core.RSTAnnotator.java
/** * Runs the parser on the given text// w ww.j a v a 2 s . c o m * * @param originalText text * @return parse tree * @throws IOException exception */ public String parseWithRST(String originalText) throws IOException { // temporary file in File tmpFileIn = File.createTempFile("rst_tmp", ".txt"); // output of RST parser is a .tree file File tmpFileOut = new File(tmpFileIn.getAbsolutePath() + ".tree"); // tmp log File tmpFileLog = new File(tmpFileIn.getAbsolutePath() + ".log"); try { // write the text into a temporary file FileUtils.writeStringToFile(tmpFileIn, originalText); String tmpDirName = System.getProperty("java.io.tmpdir"); File rstParserSrcDir = new File(rstParserSrcDirPath); // create process ProcessBuilder processBuilder = new ProcessBuilder().inheritIO(); // log to file processBuilder.redirectErrorStream(true); processBuilder.redirectOutput(ProcessBuilder.Redirect.to(tmpFileLog)); // working dir must be set to the src dir of RST parser processBuilder.directory(rstParserSrcDir); // run the command processBuilder.command("python", new File(rstParserSrcDir, "parse.py").getAbsolutePath(), "-t", tmpDirName, tmpFileIn.getAbsolutePath(), "-g"); Process process = processBuilder.start(); // and wait int returnValue = process.waitFor(); if (returnValue != 0) { throw new RuntimeException("Process exited with code " + returnValue); } // read the log if (this.debugRSTOutput) { getLogger().debug(FileUtils.readFileToString(tmpFileLog)); } // read the output if (tmpFileOut.exists()) { return FileUtils.readFileToString(tmpFileOut); } } catch (InterruptedException e) { throw new IOException(e); } finally { // clean up if (!keepTmpFiles) { FileUtils.deleteQuietly(tmpFileIn); FileUtils.deleteQuietly(tmpFileOut); FileUtils.deleteQuietly(tmpFileLog); } } return null; }
From source file:com.dsdev.mupdate.MainForm.java
private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened //Set window properties this.setLocationRelativeTo(null); this.setIconImage(Resources.getImageResource("icon.png").getImage()); popupDialog.setIconImage(Resources.getImageResource("icon.png").getImage()); UpdateLogoLabel.setIcon(Resources.getImageResource("update.png")); popupDialogImageLabel.setIcon(Resources.getImageResource("alert.png")); SimpleSwingWorker worker = new SimpleSwingWorker() { @Override/* w w w . j a v a 2 s .com*/ protected void task() { //Copy updates copyDirectoryAndBackUpOldFiles(new File("./launcherpatch"), new File("..")); //Load version config JSONObject versionConfig; try { versionConfig = (JSONObject) JSONValue .parse(FileUtils.readFileToString(new File("./version.json"))); } catch (IOException ex) { showPopupDialog("Warning: The version file could not be updated! This may cause problems."); System.exit(0); return; } //Get new version from arguments String newVersion = "0"; for (String arg : Arguments) { if (arg.startsWith("--version=")) { newVersion = arg.substring(10); break; } } //Save new version file try { versionConfig.put("moddleversion", newVersion); FileUtils.writeStringToFile(new File("./version.json"), versionConfig.toJSONString()); } catch (IOException ex) { showPopupDialog("Warning: The version file could not be updated! This may cause problems."); System.exit(0); return; } //Start Moddle try { ProcessBuilder moddle = new ProcessBuilder(new String[] { "javaw.exe", "-jar", "\"" + new File("../Moddle.jar").getCanonicalPath() + "\"" }); moddle.directory(new File("..")); moddle.start(); } catch (IOException ex) { try { ProcessBuilder moddle = new ProcessBuilder( new String[] { "javaw.exe", "-jar", "\"../Moddle.jar\"" }); moddle.directory(new File("..")); moddle.start(); } catch (IOException ex2) { showPopupDialog("Failed to start Moddle!"); } } //Exit System.exit(0); } }; worker.execute(); }