List of usage examples for java.lang Process exitValue
public abstract int exitValue();
From source file:kaleidoscope.server.UploadHandler.java
public UploadHandler(final RestRequestHandler handler, final HttpServerRequest req, final Set<String> supportImageFormat) throws URISyntaxException { this.handler = handler; this.req = req; this.rootPath = handler.getRootPath(); final String defaultOutfileExt = handler.getDefaultOutfileExt(); final String defaultResize = handler.getDefaultResize(); final int maxUploadFileSize = handler.getMaxUploadFileSize(); final int maxThumbnailCount = handler.getMaxThumbnailCount(); final int expireSec = handler.getExpireSec(); final String readUrl = handler.getReadUrl(); this.supportImageFormat = supportImageFormat; final String realCmd = Paths.get(getClass().getClassLoader().getResource(handler.getCmd()).toURI()) .toString();// ww w . ja v a2 s . c o m req.endHandler(new Handler<Void>() { @Override public void handle(Void event) { try { if (file == null) { handler.requestEnd(req, HttpResponseStatus.BAD_REQUEST, new Object[] { "required.param.file" }); return; } else if (FileUtils.getSize(file) > maxUploadFileSize) { handler.requestEnd(req, HttpResponseStatus.BAD_REQUEST, new Object[] { "max.upload.file.size", maxUploadFileSize }); return; } else if (supportImageFormat.contains(ext) != true) { handler.requestEnd(req, HttpResponseStatus.BAD_REQUEST, new Object[] { "invalid.image.format", supportImageFormat }); return; } String resizes = req.formAttributes().get("resizes"); if ((resizes == null) || ((resizes = resizes.trim()).length() == 0)) { resizes = defaultResize; } String[] resizeList = resizes.split(","); if (resizeList.length > maxThumbnailCount) { handler.requestEnd(req, HttpResponseStatus.BAD_REQUEST, new Object[] { "max.thumbnail.count", maxThumbnailCount }); return; } String outfilePrefix = path + "/" + basename; String outfileExt = req.formAttributes().get("outfileExt"); if (StringUtils.isEmpty(outfileExt) == true) { outfileExt = defaultOutfileExt; } Runtime runtime = Runtime.getRuntime(); String command = realCmd + " " + Paths.get(file) + " " + Paths.get(outfilePrefix) + " " + outfileExt + " " + resizes; Process process = runtime.exec(command); process.waitFor(); log.debug("cmd=[{}], exitValue=[{}]", command, process.exitValue()); JsonArray arr = new JsonArray(); for (int i = 0; i < resizeList.length; i++) { arr.add(readUrl + outfilePrefix.replaceAll(rootPath, "") + "_" + resizeList[i] + "." + outfileExt); } Calendar expireDate = DateUtils.getCalendar(expireSec); expireDate.set(Calendar.SECOND, 0); JsonObject json = JsonUtils.getJson(HttpResponseStatus.OK).putArray("thumbnails", arr) .putString("expireDate", DateUtils.DATE_FORMAT_ISO8601FMT.format(expireDate.getTime())); handler.requestEnd(req, HttpResponseStatus.OK, json); FileUtils.rmdir(file); } catch (Exception e) { log.error("e={}", e.getMessage(), e); handler.requestEnd(req, HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage()); } } }); log.debug( "rootPath={}, cmd={}, defaultOutfileExt={}, defaultResize={}" + ", maxUploadFileSize={}, maxThumbnailCount={}" + ", expireSec={}, readUrl={}, supportImageFormat={}", new Object[] { rootPath, realCmd, defaultOutfileExt, defaultResize, maxUploadFileSize, maxThumbnailCount, expireSec, readUrl, supportImageFormat }); }
From source file:jeplus.INSELWinTools.java
/** * Call INSEL executable file to run the simulation * @param config INSEL Configuration// w w w. j a va2 s. c om * @param WorkDir The working directory where the input files are stored and the output files to be generated * @param useReadVars Whether or not to use readvars after simulation * @return the result code represents the state of execution steps. >=0 means successful */ public static int runINSEL(INSELConfig config, String WorkDir, String modelfile) { int ExitValue = -99; try { // Trace simulation time Date start = new Date(); // Run EnergyPlus executable String CmdLine = config.getResolvedInselEXEC() + " " + modelfile; Process EPProc = Runtime.getRuntime().exec(CmdLine, null, new File(WorkDir)); BufferedReader ins = new BufferedReader(new InputStreamReader(EPProc.getInputStream())); // Use console output as the report file BufferedWriter outs = new BufferedWriter(new FileWriter(WorkDir + config.ScreenFile, false)); outs.newLine(); outs.write("Calling insel.exe - " + (new SimpleDateFormat()).format(start)); outs.newLine(); outs.write("Command line: " + WorkDir + ">" + CmdLine); outs.newLine(); int res = ins.read(); while (res != -1) { outs.write(res); res = ins.read(); } ins.close(); outs.newLine(); outs.write("Simulation time: " + Long.toString((new Date().getTime() - start.getTime()) / 1000) + " seconds"); outs.flush(); outs.close(); EPProc.waitFor(); ExitValue = EPProc.exitValue(); } catch (IOException | InterruptedException e) { logger.error("Exception during INSEL execution.", e); } // Return Radiance exit value return ExitValue; }
From source file:org.globusonline.transfer.DelegateProxyActivation.java
/** * Create a proxy certificate using the provided public key and signed * by the provided credential./*w w w.j a v a 2 s . co m*/ * * Appends the certificate chain to proxy certificate, and returns as PEM. * Uses an external program to construct the certificate; see * https://github.com/globusonline/transfer-api-client-python/tree/master/mkproxy * @param publicKeyPem String containing a PEM encoded RSA public key * @param credentialPem String containing a PEM encoded credential, with * certificate, private key, and trust chain. * @param hours Hours the certificate will be valid for. */ public String createProxyCertificate(String publicKeyPem, String credentialPem, int hours) throws IOException, InterruptedException { Process p = new ProcessBuilder(mkproxyPath, "" + hours).start(); DataOutputStream out = new DataOutputStream(p.getOutputStream()); out.writeBytes(publicKeyPem); out.writeBytes(credentialPem); out.close(); p.waitFor(); if (p.exitValue() != 0) { InputStreamReader in = new InputStreamReader(p.getErrorStream()); String err = readEntireStream(in); throw new IOException("Returned with code " + p.exitValue() + ": " + err); } InputStreamReader in = new InputStreamReader(p.getInputStream()); String certChain = readEntireStream(in); return certChain; }
From source file:io.hops.hopsworks.api.zeppelin.util.ZeppelinResource.java
private boolean isProccessAlive(String pid) { String[] command = { "kill", "-0", pid }; ProcessBuilder pb = new ProcessBuilder(command); if (pid == null) { return false; }// ww w.ja v a2 s . c om //TODO: We should clear the environment variables before launching the // redirect stdout and stderr for child process to the zeppelin/project/logs file. int exitValue; try { Process p = pb.start(); p.waitFor(); exitValue = p.exitValue(); } catch (IOException | InterruptedException ex) { logger.log(Level.WARNING, "Problem testing Zeppelin Interpreter: {0}", ex.toString()); //if the pid file exists but we can not test if it is alive then //we answer true, b/c pid files are deleted when a process is killed. return true; } return exitValue == 0; }
From source file:org.apache.nifi.bootstrap.RunNiFi.java
public static boolean isAlive(final Process process) { try {/*from w w w .j a va 2 s .co m*/ process.exitValue(); return false; } catch (final IllegalStateException | IllegalThreadStateException itse) { return true; } }
From source file:org.jajuk.util.UtilSystem.java
/** * Return whether a process is still running. * /*from w w w . java 2s. co m*/ * @param process the process * * @return whether the process is still running */ public static boolean isRunning(Process process) { try { process.exitValue(); return false; } catch (IllegalThreadStateException itse) { return true; } }
From source file:dpfmanager.shell.modules.periodic.core.ControllerWindows.java
@Override public boolean savePeriodicalCheck(PeriodicCheck check) { try {/*from w w w .java2s . c o m*/ createIfNotExistsVBS(); String params = buildCommandArguments(check); String exe = asString(getVBSPath()); String dpfCommand = "wscript.exe " + exe + " " + params; String command = ""; Periodicity periodicity = check.getPeriodicity(); switch (periodicity.getMode()) { case DAILY: command = "schtasks /create /tn \"" + check.getUuid() + "\" /tr \"" + dpfCommand + "\" /sc daily /st " + periodicity.getTimeString(); break; case WEEKLY: command = "schtasks /create /tn \"" + check.getUuid() + "\" /tr \"" + dpfCommand + "\" /sc weekly /d " + parseDaysOfWeek(periodicity.getDaysOfWeek()) + " /st " + periodicity.getTimeString(); break; case MONTHLY: command = "schtasks /create /tn \"" + check.getUuid() + "\" /tr \"" + dpfCommand + "\" /sc monthly /d " + periodicity.getDayOfMonth() + " /st " + periodicity.getTimeString(); break; } // Run command Process proc = Runtime.getRuntime().exec(command); proc.waitFor(); return (proc.exitValue() == 0); } catch (Exception e) { return false; } }
From source file:org.jajuk.util.UtilSystem.java
/** * Return a process exit value, -100 if the process is still running. * /*from ww w . ja va2 s . c o m*/ * @param process the process * * @return the process exit value, -100 if the process is still running */ public static int getExitValue(Process process) { try { return process.exitValue(); } catch (IllegalThreadStateException itse) { return -100; } }
From source file:com.orange.clara.cloud.servicedbdumper.acceptance.AcceptanceExternalTest.java
protected boolean isCfCliPluginAvailable() { Runtime rt = Runtime.getRuntime(); Process proc = null; try {//from ww w . j a v a 2 s. c om proc = rt.exec(this.dbDumperCli()); proc.waitFor(); } catch (IOException | InterruptedException e) { return false; } int exitVal = proc.exitValue(); return exitVal == 0; }
From source file:org.apache.fop.visual.ConvertUtils.java
/** * Calls an external converter application (GhostScript, for example). * @param cmd the full command//from w w w . ja va 2 s. co m * @param envp array of strings, each element of which has environment variable settings * in format name=value. * @param workDir the working directory of the subprocess, or null if the subprocess should * inherit the working directory of the current process. * @param log the logger to log output by the external application to * @throws IOException in case the external call fails */ public static void convert(String cmd, String[] envp, File workDir, final Log log) throws IOException { log.debug(cmd); Process process = null; try { process = Runtime.getRuntime().exec(cmd, envp, null); //Redirect stderr output RedirectorLineHandler errorHandler = new AbstractRedirectorLineHandler() { public void handleLine(String line) { log.error("ERR> " + line); } }; StreamRedirector errorRedirector = new StreamRedirector(process.getErrorStream(), errorHandler); //Redirect stdout output RedirectorLineHandler outputHandler = new AbstractRedirectorLineHandler() { public void handleLine(String line) { log.debug("OUT> " + line); } }; StreamRedirector outputRedirector = new StreamRedirector(process.getInputStream(), outputHandler); new Thread(errorRedirector).start(); new Thread(outputRedirector).start(); process.waitFor(); } catch (java.lang.InterruptedException ie) { throw new IOException("The call to the external converter failed: " + ie.getMessage()); } catch (java.io.IOException ioe) { throw new IOException("The call to the external converter failed: " + ioe.getMessage()); } int exitValue = process.exitValue(); if (exitValue != 0) { throw new IOException("The call to the external converter failed. Result: " + exitValue); } }