List of usage examples for java.lang Process exitValue
public abstract int exitValue();
From source file:io.pcp.parfait.dxm.PcpClient.java
String getMetric(String metricName) throws Exception { Process exec = Runtime.getRuntime().exec("pmdumptext -s 1 -t 0.001 -r " + metricName); exec.waitFor();//from www. j a v a2 s. c o m if (exec.exitValue() != 0) { throw new PcpFetchException(exec); } String result = IOUtils.toString(exec.getInputStream()); Pattern pattern = Pattern.compile("\t(.*?)\n"); Matcher matcher = pattern.matcher(result); if (matcher.find()) { return matcher.group(1); } throw new PcpFetchException("Could not find metric in the output: " + result); }
From source file:husky.server.HuskyMaster.java
@Override public void run() { try {//from w ww .j ava 2 s.co m LOG.info("Starting husky master process"); ProcessBuilder mHuskyMasterProcess = new ProcessBuilder(getCommands()); if (!mAppMaster.getLdLibraryPath().isEmpty()) { mHuskyMasterProcess.environment().put("LD_LIBRARY_PATH", mAppMaster.getLdLibraryPath()); } mHuskyMasterProcess.redirectOutput(new File(mAppMaster.getAppMasterLogDir() + "/HuskyMaster.stdout")); mHuskyMasterProcess.redirectError(new File(mAppMaster.getAppMasterLogDir() + "/HuskyMaster.stderr")); Process p = mHuskyMasterProcess.start(); p.waitFor(); if (p.exitValue() == 0) { LOG.info("Husky master exits successfully"); } else { LOG.info("Husky master exits with code " + p.exitValue()); } } catch (Exception e) { LOG.log(Level.SEVERE, " Failed to start c++ husky master process: ", e); } finally { if (!mAppMaster.getLogPathToHDFS().isEmpty()) { try { mAppMaster.getFileSystem().copyFromLocalFile(false, true, new Path[] { new Path(mAppMaster.getAppMasterLogDir() + "/HuskyMaster.stdout"), new Path(mAppMaster.getAppMasterLogDir() + "/HuskyMaster.stderr") }, new Path(mAppMaster.getLogPathToHDFS())); } catch (IOException e) { LOG.log(Level.INFO, "Failed to upload logs of husky master to hdfs", e); } } } }
From source file:org.jts.gui.exportCJSIDL.Export.java
public static void exportServiceDefCJSIDL(com.u2d.generated.ServiceDef serviceDef, File outputFile) { lastServiceDefExportPath = outputFile.getParentFile(); com.u2d.app.Context.getInstance().getViewMechanism().message("Exporting ServiceDef... "); org.jts.jsidl.binding.ServiceDef sd = org.jts.gui.jmatterToJAXB.ServiceDef.convert(serviceDef); RemoveJSIDLPlus.removeJSIDLPlus(sd); if (hasDependencies(sd)) { com.u2d.app.Context.getInstance().getViewMechanism().message( "ServiceDef Conversion Failed! Dependencies detected, but not included.\n This should be done using a service set. "); JOptionPane.showMessageDialog(GUI.getFrame(), "ServiceDef Conversion Failed!\n" + "Dependencies detected, but not included.\n" + "Try exporting a service set that includes all dependencies."); return;/*from w w w. j a va2 s. co m*/ } try { java.util.List<File> files = new ArrayList<File>(); File tmpfolder = org.jts.gui.importCJSIDL.Import.createTempDir(); File tmpfile = null; try { tmpfile = serializeJAXB(sd, tmpfolder.getCanonicalPath()); files.add(tmpfile); } catch (FileNotFoundException ex) { System.out.println( "Failed to create a temp file used during conversion: " + tmpfile.getCanonicalPath()); } // convertFromJSIDL tmpfile.getCanonicalPath() outputFile.getCanonicalPath() // this could be done instead of the following try/catch, but an antlr lib version conflict gets in the way // Conversion conv = new Conversion(); // conv.convertFromJSIDL(tmpfile.getCanonicalPath(), outputFile.getCanonicalPath()); try { System.out.println("Initiating Conversion process 'convertFromJSIDL'"); java.lang.Runtime rt = java.lang.Runtime.getRuntime(); String execStr = ("java " + classpath + " org.jts.eclipse.conversion.cjsidl.Conversion \"convertFromJSIDL\" \"" + tmpfile.getCanonicalPath() + "\" \"" + outputFile.getCanonicalPath() + "\""); // if this is Linux or Mac OS X, we can't have double quotes around the // parameters, and classpath uses : instead of ; if (!System.getProperty("os.name").startsWith("Windows")) { execStr = execStr.replace("\"", ""); execStr = execStr.replace(";", ":"); } java.lang.Process p = rt.exec(execStr); StreamReader gerrors = new StreamReader(p.getErrorStream(), "ERROR"); StreamReader goutput = new StreamReader(p.getInputStream(), "OUTPUT"); gerrors.start(); goutput.start(); try { p.waitFor(); } catch (InterruptedException ex) { Logger.getLogger(Export.class.getName()).log(Level.SEVERE, null, ex); } String errors = gerrors.getData(); String log = goutput.getData(); System.out.println("Process exited with code = " + p.exitValue()); if (!errors.isEmpty()) { Logger.getLogger(Export.class.getName()).log(Level.SEVERE, errors); JOptionPane.showMessageDialog(GUI.getFrame(), errors, "CJSIDL Export Error", JOptionPane.ERROR_MESSAGE); } } catch (IOException ex) { Logger.getLogger(Export.class.getName()).log(Level.SEVERE, null, ex); } com.u2d.app.Context.getInstance().getViewMechanism().message("ServiceDef Export Complete! "); } catch (IOException ex) { String message = "Invalid path or file name when exporting a service def: " + outputFile; System.out.println(message); throw new ExportException(message, ex); } }
From source file:gov.nasa.jpf.symbc.tree.visualizer.DOTVisualizerListener.java
private void convertDotFile(File file, OUTPUT_FORMAT format) throws InterruptedException { String dotCmd = "dot " + file.getPath() + " -T" + format.getFormat() + " -o " + file.getPath().replace(".dot", "." + format.getFormat()); try {//from ww w . ja v a 2s.c o m Process p = Runtime.getRuntime().exec(dotCmd); p.waitFor(); p.exitValue(); p.destroy(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Browser.java
/** * Open the specified URL in the client web browser. * //from w w w . j a va 2s . c o m * @param url URL to open. * @throws IOException If there is brwoser problem. */ public static void openUrl(String url) throws IOException { if (!loadedWithoutErrors) { throw new IOException("Exception in finding browser: " + errorMessage); } Object browser = locateBrowser(); if (browser == null) { throw new IOException("Unable to locate browser: " + errorMessage); } switch (jvm) { case MRJ_2_0: Object aeDesc = null; try { aeDesc = aeDescConstructor.newInstance(new Object[] { url }); putParameter.invoke(browser, new Object[] { keyDirectObject, aeDesc }); sendNoReply.invoke(browser, new Object[] {}); } catch (InvocationTargetException ite) { throw new IOException("InvocationTargetException while creating AEDesc: " + ite.getMessage()); } catch (IllegalAccessException iae) { throw new IOException("IllegalAccessException while building AppleEvent: " + iae.getMessage()); } catch (InstantiationException ie) { throw new IOException("InstantiationException while creating AEDesc: " + ie.getMessage()); } finally { aeDesc = null; // Encourage it to get disposed if it was created browser = null; // Ditto } break; case MRJ_2_1: Runtime.getRuntime().exec(new String[] { (String) browser, url }); break; case MRJ_3_0: int[] instance = new int[1]; int result = ICStart(instance, 0); if (result == 0) { int[] selectionStart = new int[] { 0 }; byte[] urlBytes = url.getBytes(); int[] selectionEnd = new int[] { urlBytes.length }; result = ICLaunchURL(instance[0], new byte[] { 0 }, urlBytes, urlBytes.length, selectionStart, selectionEnd); if (result == 0) { // Ignore the return value; the URL was launched successfully // regardless of what happens here. ICStop(instance); } else { throw new IOException("Unable to launch URL: " + result); } } else { throw new IOException("Unable to create an Internet Config instance: " + result); } break; case MRJ_3_1: try { openURL.invoke(null, new Object[] { url }); } catch (InvocationTargetException ite) { throw new IOException("InvocationTargetException while calling openURL: " + ite.getMessage()); } catch (IllegalAccessException iae) { throw new IOException("IllegalAccessException while calling openURL: " + iae.getMessage()); } break; case WINDOWS_NT: case WINDOWS_9x: // Add quotes around the URL to allow ampersands and other special // characters to work. Process process = Runtime.getRuntime().exec(new String[] { (String) browser, FIRST_WINDOWS_PARAMETER, SECOND_WINDOWS_PARAMETER, THIRD_WINDOWS_PARAMETER, '"' + url + '"' }); // This avoids a memory leak on some versions of Java on Windows. // That's hinted at in <http://developer.java.sun.com/developer/qow/ // archive/68/>. try { process.waitFor(); process.exitValue(); } catch (InterruptedException ie) { throw new IOException("InterruptedException while launching browser: " + ie.getMessage()); } break; case OTHER: // Assume that we're on Unix and that Netscape is installed // First, attempt to open the URL in a currently running session of // Netscape String command = browser.toString() + " -raise " + NETSCAPE_REMOTE_PARAMETER + " " + NETSCAPE_OPEN_PARAMETER_START + url + NETSCAPE_OPEN_PARAMETER_END; process = Runtime.getRuntime().exec(command); try { int exitCode = process.waitFor(); if (exitCode != 0) { // if Netscape was not open Runtime.getRuntime().exec(new String[] { (String) browser, url }); } } catch (InterruptedException exception) { exception.printStackTrace(); throw new IOException("InterruptedException while launching browser: " + exception.getMessage()); } break; default: // This should never occur, but if it does, we'll try the simplest // thing possible Runtime.getRuntime().exec(new String[] { (String) browser, url }); break; } }
From source file:de.teamgrit.grit.preprocess.fetch.SvnFetcher.java
/** * runSVNCommand runs an svn command in the specified directory. * * @param connection/* ww w .j ava 2 s. c o m*/ * the connection storing the connection infos for the remote * @param svnCommand * is the command to be executed. Each part of the command must * be a string element. For example: "svn" "checkout" * "file://some/path" * @param workingDir * where the svn command should be executed (must be a * repository). * @return A list of all output lines. * @throws IOException * Thrown when process can't be started or an error occurs * while reading its output */ private static SVNResultData runSVNCommand(Connection connection, List<String> svnCommand, Path workingDir) throws IOException { // add boilerplate to command svnCommand.add("--non-interactive"); svnCommand.add("--no-auth-cache"); svnCommand.add("--force"); if ((connection.getUsername() != null) && !connection.getUsername().isEmpty()) { svnCommand.add("--username"); svnCommand.add(connection.getUsername()); } if ((connection.getPassword() != null) && !connection.getPassword().isEmpty()) { svnCommand.add("--password"); svnCommand.add(connection.getPassword()); } // build process: construct command and set working directory. Process svnProcess = null; ProcessBuilder svnProcessBuilder = new ProcessBuilder(svnCommand); svnProcessBuilder.directory(workingDir.toFile()); svnProcess = svnProcessBuilder.start(); try { svnProcess.waitFor(); } catch (InterruptedException e) { LOGGER.severe("Interrupted while waiting for SVN. " + "Cannot guarantee clean command run!"); return null; } InputStream svnOutputStream = svnProcess.getInputStream(); InputStreamReader svnStreamReader = new InputStreamReader(svnOutputStream); BufferedReader svnOutputBuffer = new BufferedReader(svnStreamReader); String line; List<String> svnOutputLines = new LinkedList<>(); while ((line = svnOutputBuffer.readLine()) != null) { svnOutputLines.add(line); } return new SVNResultData(svnProcess.exitValue(), svnOutputLines); }
From source file:org.hyperic.hq.plugin.system.OtherUnixCollector.java
@Override public void collect() { log.info("[collect]"); Process cmd; try {/* ww w . j av a 2 s .c o m*/ cmd = Runtime.getRuntime().exec(VMSTAT); cmd.waitFor(); if (cmd.exitValue() != 0) { String msg = inputStreamAsString(cmd.getErrorStream()); log.info("[collect] cmd error: " + msg); setErrorMessage(msg); } else { Map<String, Double> stats = parseVMStat(cmd.getInputStream()); for (String[] metric : METRICS) { final Double val = stats.get(metric[1]); log.info("[collect] " + metric[0] + "=" + val); if (val != null) { setValue(metric[0], val); } } } } catch (IOException e) { log.info("[collect] error: " + e.getMessage(), e); setErrorMessage(e.getLocalizedMessage(), e); } catch (InterruptedException e) { log.info("[collect] error: " + e.getMessage(), e); setErrorMessage(e.getLocalizedMessage(), e); } }
From source file:de.jcup.egradle.eclipse.ide.execution.EclipseLaunchProcessExecutor.java
@Override protected void handleProcessEnd(Process p) { if (postJob != null) { postJob.setBuildInfo(new BuildInfo(cmdLine, p.exitValue())); postJob.schedule();//from w ww . ja v a 2 s .c o m } }
From source file:org.noroomattheinn.utils.ThreadManager.java
private boolean hasExited(Process p) { try {//from w ww . j a va 2s . co m p.exitValue(); // An exception will be raised if it hasn't exited yet return true; } catch (IllegalThreadStateException e) { return false; } }
From source file:org.sdw.mapping.R2RMLmapper.java
/** * Execute command on local shell//from w ww.j av a 2s .c o m * @param command : Command to be executed * @return : A string array with exit code and output of execution */ private String[] executeCommandShell(String command) { StringBuffer op = new StringBuffer(); String out[] = new String[2]; Process process; try { process = Runtime.getRuntime().exec(command); process.waitFor(); int exitStatus = process.exitValue(); out[0] = "" + exitStatus; BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { op.append(line + "\n"); } out[1] = op.toString(); } catch (Exception e) { LOG.error(e.getMessage(), e); } return out; }