List of usage examples for java.lang ProcessBuilder redirectError
public ProcessBuilder redirectError(File file)
From source file:org.apache.zeppelin.python.IPythonInterpreter.java
/** * non-empty return value mean the errors when checking ipython prerequisite. * empty value mean IPython prerequisite is meet. * * @param pythonExec// w w w . ja va 2s . c o m * @return */ public String checkIPythonPrerequisite(String pythonExec) { ProcessBuilder processBuilder = new ProcessBuilder(pythonExec, "-m", "pip", "freeze"); try { File stderrFile = File.createTempFile("zeppelin", ".txt"); processBuilder.redirectError(stderrFile); File stdoutFile = File.createTempFile("zeppelin", ".txt"); processBuilder.redirectOutput(stdoutFile); Process proc = processBuilder.start(); int ret = proc.waitFor(); if (ret != 0) { return "Fail to run pip freeze.\n" + IOUtils.toString(new FileInputStream(stderrFile)); } String freezeOutput = IOUtils.toString(new FileInputStream(stdoutFile)); if (!freezeOutput.contains("jupyter-client=")) { return "jupyter-client is not installed."; } if (!freezeOutput.contains("ipykernel=")) { return "ipykernel is not installed"; } if (!freezeOutput.contains("ipython=")) { return "ipython is not installed"; } if (!freezeOutput.contains("grpcio=")) { return "grpcio is not installed"; } if (!freezeOutput.contains("protobuf=")) { return "protobuf is not installed"; } LOGGER.info("IPython prerequisite is met"); } catch (Exception e) { LOGGER.warn("Fail to checkIPythonPrerequisite", e); return "Fail to checkIPythonPrerequisite: " + ExceptionUtils.getStackTrace(e); } return ""; }
From source file:de.huberlin.wbi.hiway.common.Worker.java
private int exec() { File script = new File("./" + containerId); script.setExecutable(true);// w w w . ja v a 2 s. c o m ProcessBuilder processBuilder = new ProcessBuilder(script.getPath()); processBuilder.directory(new File(".")); Process process; int exitValue = -1; try { File stdOutFile = new File(Invocation.STDOUT_FILENAME); File stdErrFile = new File(Invocation.STDERR_FILENAME); processBuilder.redirectOutput(stdOutFile); processBuilder.redirectError(stdErrFile); process = processBuilder.start(); exitValue = process.waitFor(); } catch (IOException | InterruptedException e) { e.printStackTrace(); System.exit(-1); } return exitValue; }
From source file:com.ecofactor.qa.automation.platform.ops.impl.IOSOperations.java
/** * Start Appium server.//from w ww . j a v a 2 s . c o m * @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:com.opentable.db.postgres.embedded.EmbeddedPostgres.java
private void startPostmaster() throws IOException { final StopWatch watch = new StopWatch(); watch.start();//from w w w . j a v a 2s. c o m Preconditions.checkState(started.getAndSet(true) == false, "Postmaster already started"); final List<String> args = Lists.newArrayList(pgBin("pg_ctl"), "-D", dataDirectory.getPath(), "-o", Joiner.on(" ").join(createInitOptions()), "start"); final ProcessBuilder builder = new ProcessBuilder(args); builder.redirectErrorStream(true); builder.redirectError(outputRedirector); builder.redirectOutput(outputRedirector); postmaster = builder.start(); LOG.info("{} postmaster started as {} on port {}. Waiting up to {}ms for server startup to finish.", instanceId, postmaster.toString(), port, PG_STARTUP_WAIT_MS); Runtime.getRuntime().addShutdownHook(newCloserThread()); waitForServerStartup(watch); }
From source file:alluxio.multi.process.MultiProcessCluster.java
/** * Copies the work directory to the artifacts folder. *//*from ww w.j a v a 2s .c o m*/ public synchronized void saveWorkdir() throws IOException { Preconditions.checkState(mState == State.STARTED, "cluster must be started before you can save its work directory"); ARTIFACTS_DIR.mkdirs(); File tarball = new File(mWorkDir.getParentFile(), mWorkDir.getName() + ".tar.gz"); // Tar up the work directory. ProcessBuilder pb = new ProcessBuilder("tar", "-czf", tarball.getName(), mWorkDir.getName()); pb.directory(mWorkDir.getParentFile()); pb.redirectOutput(Redirect.appendTo(TESTS_LOG)); pb.redirectError(Redirect.appendTo(TESTS_LOG)); Process p = pb.start(); try { p.waitFor(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } // Move tarball to artifacts directory. File finalTarball = new File(ARTIFACTS_DIR, tarball.getName()); FileUtils.moveFile(tarball, finalTarball); LOG.info("Saved cluster {} to {}", mClusterName, finalTarball.getAbsolutePath()); }
From source file:fr.amap.lidar.RxpScanConversion.java
public void toLaz(SimpleScan scan, File outputDirectory, boolean laz, boolean exportIntensity) throws IOException, InterruptedException, UnsupportedOperationException, Exception { /***Convert rxp to txt***/ Mat4D transfMatrix = Mat4D.multiply(scan.sopMatrix, scan.popMatrix); Mat3D rotation = new Mat3D(); rotation.mat = new double[] { transfMatrix.mat[0], transfMatrix.mat[1], transfMatrix.mat[2], transfMatrix.mat[4], transfMatrix.mat[5], transfMatrix.mat[6], transfMatrix.mat[8], transfMatrix.mat[9], transfMatrix.mat[10] }; File outputTxtFile = new File( outputDirectory.getAbsolutePath() + File.separator + scan.file.getName() + ".txt"); BufferedWriter writer = new BufferedWriter(new FileWriter(outputTxtFile)); RxpExtraction extraction = new RxpExtraction(); extraction.openRxpFile(scan.file, RxpExtraction.REFLECTANCE); Iterator<Shot> iterator = extraction.iterator(); while (iterator.hasNext()) { Shot shot = iterator.next();//w w w.ja v a 2 s. c o m Vec4D origin = Mat4D.multiply(transfMatrix, new Vec4D(shot.origin.x, shot.origin.y, shot.origin.z, 1.0d)); Vec3D direction = Mat3D.multiply(rotation, new Vec3D(shot.direction.x, shot.direction.y, shot.direction.z)); for (int i = 0; i < shot.nbEchos; i++) { double x = origin.x + direction.x * shot.ranges[i]; double y = origin.y + direction.y * shot.ranges[i]; double z = origin.z + direction.z * shot.ranges[i]; if (exportIntensity) { writer.write(x + " " + y + " " + z + " " + (i + 1) + " " + shot.nbEchos + " " + reflectanceToIntensity(shot.reflectances[i]) + "\n"); } else { writer.write(x + " " + y + " " + z + " " + (i + 1) + " " + shot.nbEchos + "\n"); } } } extraction.close(); writer.close(); /***Convert txt to laz***/ String propertyValue = System.getProperty("user.dir"); System.out.println("Current jar directory : " + propertyValue); String txtToLasPath; String osName = getOSName(); switch (osName) { case "windows": case "linux": txtToLasPath = propertyValue + File.separator + "LASTools" + File.separator + osName + File.separator + "txt2las"; break; default: throw new UnsupportedOperationException("Os architecture not supported"); } if (osName.equals("windows")) { txtToLasPath = txtToLasPath + ".exe"; } File outputLazFile; if (laz) { outputLazFile = new File( outputDirectory.getAbsolutePath() + File.separator + scan.file.getName() + ".laz"); } else { outputLazFile = new File( outputDirectory.getAbsolutePath() + File.separator + scan.file.getName() + ".las"); } String[] commandLine; if (exportIntensity) { commandLine = new String[] { txtToLasPath, "-i", outputTxtFile.getAbsolutePath(), "-o", outputLazFile.getAbsolutePath(), "-parse", "xyzrni" }; } else { commandLine = new String[] { txtToLasPath, "-i", outputTxtFile.getAbsolutePath(), "-o", outputLazFile.getAbsolutePath(), "-parse", "xyzrn" }; } System.out.println("Command line : " + ArrayUtils.toString(commandLine).replaceAll(",", " ").replaceAll("}", "").replace("{", "")); ProcessBuilder pb = new ProcessBuilder(commandLine); pb.redirectOutput(ProcessBuilder.Redirect.INHERIT); pb.redirectError(ProcessBuilder.Redirect.INHERIT); Process p = pb.start(); p.waitFor(); }
From source file:com.axelor.studio.service.ModuleRecorderService.java
private String restartServer(boolean reset) throws AxelorException { String logFile = checkParams("studio.restart.log", AppSettings.get().get("studio.restart.log"), true); String warPath = getWarPath(); try {//from w ww.j av a 2 s .c om String scriptPath = getRestartScriptPath(); ProcessBuilder processBuilder; if (reset) { processBuilder = new ProcessBuilder(scriptPath, warPath, "reset"); } else { processBuilder = new ProcessBuilder(scriptPath, warPath); } processBuilder.environment().putAll(ENV); processBuilder.redirectOutput(new File(logFile)); processBuilder.redirectError(new File(logFile)); processBuilder.start(); } catch (IOException e) { throw new AxelorException(e, 5); } if (reset) { return I18n.get("App reset sucessfully"); } return I18n.get("App updated successfully"); }
From source file:org.apache.hadoop.hive.llap.cli.LlapServiceDriver.java
private int runPackagePy(String[] args, Path tmpDir, Path scriptParent, String version, String outputDir) throws IOException, InterruptedException { Path scriptPath = new Path(new Path(scriptParent, "slider"), "package.py"); List<String> scriptArgs = new ArrayList<>(args.length + 7); scriptArgs.add("python"); scriptArgs.add(scriptPath.toString()); scriptArgs.add("--input"); scriptArgs.add(tmpDir.toString());/*from www . ja v a 2 s. co m*/ scriptArgs.add("--output"); scriptArgs.add(outputDir); scriptArgs.add("--javaChild"); for (String arg : args) { scriptArgs.add(arg); } LOG.debug("Calling package.py via: " + scriptArgs); ProcessBuilder builder = new ProcessBuilder(scriptArgs); builder.redirectError(ProcessBuilder.Redirect.INHERIT); builder.redirectOutput(ProcessBuilder.Redirect.INHERIT); builder.environment().put("HIVE_VERSION", version); return builder.start().waitFor(); }
From source file:org.opencms.workplace.tools.git.CmsGitCheckin.java
/** * Runs the shell script for committing and optionally pushing the changes in the module. * @return exit code of the script.//from w w w . j a v a 2 s .c om */ private int runCommitScript() { if (m_checkout && !m_fetchAndResetBeforeImport) { m_logStream.println("Skipping script...."); return 0; } try { m_logStream.flush(); String commandParam; if (m_resetRemoteHead) { commandParam = resetRemoteHeadScriptCommand(); } else if (m_resetHead) { commandParam = resetHeadScriptCommand(); } else if (m_checkout) { commandParam = checkoutScriptCommand(); } else { commandParam = checkinScriptCommand(); } String[] cmd = { "bash", "-c", commandParam }; m_logStream.println("Calling the script as follows:"); m_logStream.println(); m_logStream.println(cmd[0] + " " + cmd[1] + " " + cmd[2]); ProcessBuilder builder = new ProcessBuilder(cmd); m_logStream.close(); m_logStream = null; Redirect redirect = Redirect.appendTo(new File(DEFAULT_LOGFILE_PATH)); builder.redirectOutput(redirect); builder.redirectError(redirect); Process scriptProcess = builder.start(); int exitCode = scriptProcess.waitFor(); scriptProcess.getOutputStream().close(); m_logStream = new PrintStream(new FileOutputStream(DEFAULT_LOGFILE_PATH, true)); return exitCode; } catch (InterruptedException | IOException e) { e.printStackTrace(m_logStream); return -1; } }
From source file:com.aurel.track.admin.customize.category.report.execute.ReportBeansToLaTeXConverter.java
/** * * @param workDir/*from w w w . ja v a 2s . co m*/ * @param latexFile */ protected int runPdflatex(File workDir, File latexFile, int nrOfRuns) { if (latexCmd == null) { return -99; } int exitValue = 0; try { String[] cmd = new String[] { latexCmd, "--halt-on-error", "-output-directory=" + workDir, latexFile.getAbsolutePath() }; String texpath = new File((new File(latexCmd)).getParent()).getAbsolutePath(); ProcessBuilder latexProcessBuilder = new ProcessBuilder(cmd); latexProcessBuilder.directory(workDir); Map<String, String> env = latexProcessBuilder.environment(); String path = env.get("PATH"); if (path != null) { path = texpath + ":" + path; env.put("PATH", path); } File stdoutlog = new File(workDir + File.separator + "stdout.log"); latexProcessBuilder.redirectOutput(Redirect.appendTo(stdoutlog)); File stderrlog = new File(workDir + File.separator + "stderr.log"); latexProcessBuilder.redirectError(Redirect.appendTo(stderrlog)); ProcessExecutor latexProcessExecutor = new ProcessExecutor(latexProcessBuilder); Thread executionThread = new Thread(latexProcessExecutor); long timeout = 20000; LOGGER.debug("Run xelatex thread started!"); long startTime = System.currentTimeMillis(); executionThread.start(); int imod = 0; while (executionThread.isAlive()) { ++imod; if (imod % 5 == 0) { LOGGER.debug("Run xelatex thread is alive"); } if (((System.currentTimeMillis() - startTime) > timeout) && executionThread.isAlive()) { executionThread.interrupt(); LOGGER.debug("Run xelatex thread interrupted!"); latexProcessExecutor.killProcess(); } Thread.sleep(100); } LOGGER.debug("Run xelatex done!"); exitValue = latexProcessExecutor.getExitValue(); try { Thread.sleep(1000); } catch (Exception ex) { LOGGER.error(ExceptionUtils.getStackTrace(ex), ex); } } catch (Exception ex) { LOGGER.error(ExceptionUtils.getStackTrace(ex), ex); } return exitValue; }