List of usage examples for java.lang Process exitValue
public abstract int exitValue();
From source file:org.eclipse.birt.build.mavenrepogen.RepoGen.java
private void exec(final String[] command, final File dir) throws IOException { final Process process = Runtime.getRuntime().exec(command, null, dir); try {/*from w w w.j av a 2 s . c o m*/ process.waitFor(); } catch (final InterruptedException e) { } if (process.exitValue() != 0) { System.out.println(command + " failed:"); System.out.println("error stream:"); pipeStream(process.getErrorStream(), System.out); System.out.println("output stream:"); pipeStream(process.getInputStream(), System.out); } }
From source file:net.ftb.minecraft.MCInstaller.java
public static void launchMinecraft(String installDir, ModPack pack, LoginResponse resp, boolean isLegacy) { try {// www. j av a 2 s . c om File packDir = new File(installDir, pack.getDir()); String gameFolder = installDir + File.separator + pack.getDir() + File.separator + "minecraft"; File gameDir = new File(packDir, "minecraft"); File assetDir = new File(installDir, "assets"); File libDir = new File(installDir, "libraries"); File natDir = new File(packDir, "natives"); final String packVer = Settings.getSettings().getPackVer(pack.getDir()); Logger.logInfo("Setting up native libraries for " + pack.getName() + " v " + packVer + " MC " + pack.getMcVersion(packVer)); if (!gameDir.exists()) gameDir.mkdirs(); if (natDir.exists()) { natDir.delete(); } natDir.mkdirs(); if (isLegacy) extractLegacy(); Version base = JsonFactory.loadVersion(new File(installDir, "versions/{MC_VER}/{MC_VER}.json".replace("{MC_VER}", pack.getMcVersion(packVer)))); byte[] buf = new byte[1024]; for (Library lib : base.getLibraries()) { if (lib.natives != null) { File local = new File(libDir, lib.getPathNatives()); ZipInputStream input = null; try { input = new ZipInputStream(new FileInputStream(local)); ZipEntry entry = input.getNextEntry(); while (entry != null) { String name = entry.getName(); int n; if (lib.extract == null || !lib.extract.exclude(name)) { File output = new File(natDir, name); output.getParentFile().mkdirs(); FileOutputStream out = new FileOutputStream(output); while ((n = input.read(buf, 0, 1024)) > -1) { out.write(buf, 0, n); } out.close(); } input.closeEntry(); entry = input.getNextEntry(); } } catch (Exception e) { ErrorUtils.tossError("Error extracting native libraries"); Logger.logError("", e); } finally { try { input.close(); } catch (IOException e) { } } } } List<File> classpath = new ArrayList<File>(); Version packjson = new Version(); if (!pack.getDir().equals("mojang_vanilla")) { if (isLegacy) { extractLegacyJson(new File(gameDir, "pack.json")); } if (new File(gameDir, "pack.json").exists()) { packjson = JsonFactory.loadVersion(new File(gameDir, "pack.json")); for (Library lib : packjson.getLibraries()) { //Logger.logError(new File(libDir, lib.getPath()).getAbsolutePath()); classpath.add(new File(libDir, lib.getPath())); } } } else { packjson = base; } if (!isLegacy) //we copy the jar to a new location for legacy classpath.add(new File(installDir, "versions/{MC_VER}/{MC_VER}.jar".replace("{MC_VER}", pack.getMcVersion(packVer)))); else { FileUtils .copyFile( new File(installDir, "versions/{MC_VER}/{MC_VER}.jar".replace("{MC_VER}", pack.getMcVersion(packVer))), new File(gameDir, "bin/" + Locations.OLDMCJARNAME)); FileUtils.killMetaInf(); } for (Library lib : base.getLibraries()) { classpath.add(new File(libDir, lib.getPath())); } Process minecraftProcess = MCLauncher.launchMinecraft(Settings.getSettings().getJavaPath(), gameFolder, assetDir, natDir, classpath, packjson.mainClass != null ? packjson.mainClass : base.mainClass, packjson.minecraftArguments != null ? packjson.minecraftArguments : base.minecraftArguments, packjson.assets != null ? packjson.assets : base.getAssets(), Settings.getSettings().getRamMax(), pack.getMaxPermSize(), pack.getMcVersion(packVer), resp.getAuth(), isLegacy); LaunchFrame.MCRunning = true; if (LaunchFrame.con != null) LaunchFrame.con.minecraftStarted(); StreamLogger.prepare(minecraftProcess.getInputStream(), new LogEntry().level(LogLevel.UNKNOWN)); String[] ignore = { "Session ID is token" }; StreamLogger.setIgnore(ignore); StreamLogger.doStart(); TrackerUtils.sendPageView(ModPack.getSelectedPack().getName() + " Launched", ModPack.getSelectedPack().getName()); try { Thread.sleep(1500); } catch (InterruptedException e) { } try { minecraftProcess.exitValue(); } catch (IllegalThreadStateException e) { LaunchFrame.getInstance().setVisible(false); LaunchFrame.setProcMonitor(ProcessMonitor.create(minecraftProcess, new Runnable() { @Override public void run() { if (!Settings.getSettings().getKeepLauncherOpen()) { System.exit(0); } else { if (LaunchFrame.con != null) LaunchFrame.con.minecraftStopped(); LaunchFrame launchFrame = LaunchFrame.getInstance(); launchFrame.setVisible(true); LaunchFrame.getInstance().getEventBus().post(new EnableObjectsEvent()); try { Settings.getSettings() .load(new FileInputStream(Settings.getSettings().getConfigFile())); LaunchFrame.getInstance().tabbedPane.remove(1); LaunchFrame.getInstance().optionsPane = new OptionsPane(Settings.getSettings()); LaunchFrame.getInstance().tabbedPane.add(LaunchFrame.getInstance().optionsPane, 1); LaunchFrame.getInstance().tabbedPane.setIconAt(1, LauncherStyle.getCurrentStyle() .filterHeaderIcon(this.getClass().getResource("/image/tabs/options.png"))); } catch (Exception e1) { Logger.logError("Failed to reload settings after launcher closed", e1); } } LaunchFrame.MCRunning = false; } })); } } catch (Exception e) { Logger.logError("Error while running launchMinecraft()", e); } }
From source file:io.hops.hopsworks.api.pythonDeps.PythonDepsService.java
private void exportEnvironment(String host, String environmentFile, String hdfsUser) throws ServiceException { String secretDir = DigestUtils.sha256Hex(project.getName() + hdfsUser); String exportPath = settings.getStagingDir() + Settings.PRIVATE_DIRS + secretDir; File exportDir = new File(exportPath); exportDir.mkdirs();//from ww w . ja v a 2s .c o m String prog = settings.getHopsworksDomainDir() + "/bin/condaexport.sh"; ProcessBuilder pb = new ProcessBuilder("/usr/bin/sudo", prog, exportPath, project.getName(), host, environmentFile, hdfsUser); try { Process process = pb.start(); process.waitFor(180l, TimeUnit.SECONDS); int exitCode = process.exitValue(); if (exitCode != 0) { throw new IOException("A problem occurred when exporting the environment. "); } } catch (IOException | InterruptedException ex) { throw new ServiceException(RESTCodes.ServiceErrorCode.ANACONDA_EXPORT_ERROR, Level.SEVERE, "host: " + host + "," + " environmentFile: " + environmentFile + ", " + "hdfsUser: " + hdfsUser, ex.getMessage(), ex); } }
From source file:org.efaps.wikiutil.export.latex.MakePDF.java
/** * Executes "<code>pdflatex</code>" from the Latex packages and * converts all Latex files to related PDF file <code>book.pdf</code>. * * @return <i>true</i> if the Latex to PDF convert was successfully; * otherwise <i>false</i> * @throws IOException if execute failed * @see #tempDir/*w w w. j a v a2 s .c o m*/ */ protected boolean executePDFLatex() throws IOException { final ProcessBuilder processBuilder = new ProcessBuilder(this.executablePdfLaTeX, "book.tex"); processBuilder.directory(this.tempDir); final Process process = processBuilder.start(); final Reader in = new InputStreamReader(process.getInputStream()); final Reader err = new InputStreamReader(process.getErrorStream()); // PrintStream out = new PrintStream(process.getOutputStream()); Integer exitCode = null; for (;;) { if (err.ready()) { System.err.print((char) err.read()); } else if (in.ready()) { System.out.print((char) in.read()); } else { try { exitCode = process.exitValue(); break; } catch (final IllegalThreadStateException e) { try { Thread.sleep(1000); } catch (final InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } } return (exitCode != null) && (exitCode == 0); }
From source file:net.sf.mavenjython.test.PythonTestMojo.java
public void execute() throws MojoExecutionException { // all we have to do is to run nose on the source directory List<String> l = new ArrayList<String>(); if (program.equals("nose")) { l.add("nosetests.bat"); l.add("--failure-detail"); l.add("--verbose"); } else {//from ww w. j a v a 2 s . com l.add(program); } ProcessBuilder pb = new ProcessBuilder(l); pb.directory(testOutputDirectory); pb.environment().put("JYTHONPATH", ".;" + outputDirectory.getAbsolutePath()); final Process p; getLog().info("starting python tests"); getLog().info("executing " + pb.command()); getLog().info("in directory " + testOutputDirectory); getLog().info("and also including " + outputDirectory); try { p = pb.start(); } catch (IOException e) { throw new MojoExecutionException( "Python tests execution failed. Provide the executable '" + program + "' in the path", e); } copyIO(p.getInputStream(), System.out); copyIO(p.getErrorStream(), System.err); copyIO(System.in, p.getOutputStream()); try { if (p.waitFor() != 0) { throw new MojoExecutionException("Python tests failed with return code: " + p.exitValue()); } else { getLog().info("Python tests (" + program + ") succeeded."); } } catch (InterruptedException e) { throw new MojoExecutionException("Python tests were interrupted", e); } }
From source file:com.orange.clara.cloud.servicedbdumper.integrations.AbstractIntegrationTest.java
protected InterruptedException generateInterruptedExceptionFromProcess(Process process) throws IOException { return new InterruptedException("\nError during process (exit code is " + process.exitValue() + "): \n" + this.getInputStreamToStringFromProcess(process.getErrorStream()) + "\n" + this.getInputStreamToStringFromProcess(process.getInputStream())); }
From source file:org.cloudifysource.usm.USMLifecycleBean.java
private Integer getProcessExitValue(final Process processToCheck) { try {/*from w w w.j a va 2 s . co m*/ return processToCheck.exitValue(); } catch (final Exception e) { return null; } }
From source file:com.taobao.adfs.util.Utilities.java
public static String runCommand(String command, Integer expectedExitCode, String extraPath, String libPath, boolean destory) throws IOException { BufferedReader stdOutputReader = null; StringBuilder output = new StringBuilder(); Process process = runCommand(command, extraPath, libPath); ;/* w w w . j a v a 2 s.c o m*/ try { stdOutputReader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = stdOutputReader.readLine()) != null) { output.append(line).append('\n'); } if (output.length() > 0) output.deleteCharAt(output.length() - 1); if (expectedExitCode != null && process.waitFor() != expectedExitCode) throw new IOException( "exit code=" + process.exitValue() + ", expected exit code=" + expectedExitCode); } catch (Throwable t) { destory = true; throw new IOException("fail to exceute " + command + ", output=" + output + (extraPath == null ? "" : ", extraPath=" + extraPath) + (libPath == null ? "" : ", libPath=" + libPath), t); } finally { if (stdOutputReader != null) stdOutputReader.close(); process.getOutputStream().close(); process.getInputStream().close(); process.getErrorStream().close(); if (destory) process.destroy(); } return output.toString(); }
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./*from www. j a v a 2s.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.pentaho.di.trans.steps.ivwloader.IngresVectorwiseLoader.java
public boolean checkSqlProcessRunning(Process sqlProcess) { try {// w w w. java2 s. co m int exitValue = sqlProcess.exitValue(); logError("SQL process exit code: " + exitValue); return false; } catch (IllegalThreadStateException e) { // ignore this exception since it is thrown when exitValue() is called on a // running process // Do nothing SQL Process still running return true; } }