List of usage examples for java.lang Process destroy
public abstract void destroy();
From source file:com.playonlinux.framework.Wine.java
private void waitWineProcess(Process process) throws CancelException { try {/*www .j a v a 2 s.c o m*/ process.waitFor(); } catch (InterruptedException e) { process.destroy(); killall(); throw new CancelException(e); } }
From source file:org.apache.syncope.fit.cli.CLIITCase.java
@Test public void roleRead() { final String roleId = "Search for realm evenTwo"; Process process = null; try {/*from ww w . ja va 2 s . c o m*/ PROCESS_BUILDER.command(getCommand(new RoleCommand().getClass().getAnnotation(Command.class).name(), RoleCommand.RoleOptions.READ.getOptionName(), roleId)); process = PROCESS_BUILDER.start(); final String result = IOUtils.toString(process.getInputStream(), StandardCharsets.UTF_8); assertTrue(result.contains(roleService.read(roleId).getEntitlements().iterator().next())); } catch (IOException e) { fail(e.getMessage()); } finally { if (process != null) { process.destroy(); } } }
From source file:org.jboss.tools.openshift.internal.ui.preferences.OpenShiftPreferencePage.java
private String findOCLocation() { String location = null;/*from w w w. j av a 2 s.c o m*/ if (SystemUtils.IS_OS_WINDOWS) { String[] paths = StringUtils.split(System.getenv("PATH"), ";"); for (String path : paths) { Collection<File> files = FileUtils.listFiles(new File(path), new IOFileFilter() { @Override public boolean accept(File file) { return ocBinary.getName().equals(file.getName()); } @Override public boolean accept(File dir, String name) { return ocBinary.getName().equals(name); } }, null); if (files.size() > 0) { location = files.iterator().next().toString(); break; } } } else { String path = ThreadUtils.runWithTimeout(WHICH_CMD_TIMEOUT, new Callable<String>() { @Override public String call() throws Exception { Process process = null; try { process = new ProcessBuilder("which", ocBinary.getName()).start(); process.waitFor(); if (process.exitValue() == WHICH_CMD_SUCCESS) { return IOUtils.toString(process.getInputStream()); } ; } catch (IOException e) { OpenShiftUIActivator.getDefault().getLogger().logError("Could not run 'which' command", e); } finally { if (process != null) { process.destroy(); } } return null; } }); if (!StringUtils.isEmpty(path)) { location = path; } } return StringUtils.trim(location); }
From source file:org.ops4j.pax.runner.platform.DefaultJavaRunner.java
/** * Create helper thread to safely shutdown the external framework process * * @param process framework process// w w w .j ava 2 s. c om * * @return stream handler */ private Thread createShutdownHook(final Process process) { LOG.debug("Wrapping stream I/O."); final Pipe errPipe = new Pipe(process.getErrorStream(), System.err).start("Error pipe"); final Pipe outPipe = new Pipe(process.getInputStream(), System.out).start("Out pipe"); final Pipe inPipe = new Pipe(process.getOutputStream(), System.in).start("In pipe"); return new Thread(new Runnable() { public void run() { Info.println(); // print an empty line LOG.debug("Unwrapping stream I/O."); inPipe.stop(); outPipe.stop(); errPipe.stop(); try { process.destroy(); } catch (Exception e) { // ignore if already shutting down } } }, "Pax-Runner shutdown hook"); }
From source file:org.rhq.maven.plugins.GenerateProjectMojo.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { Process process = null; try {//from w w w . java 2 s.c o m String generatorClasspath = buildGeneratorClasspath(); String javaCommand = buildJavaCommand(); ProcessBuilder processBuilder = buildProcessBuilder(javaCommand, generatorClasspath); process = processBuilder.start(); redirectInput(process); redirectOuput(process); int exitCode = process.waitFor(); if (exitCode != 0) { throw new MojoFailureException("Process terminated with exitCode=" + exitCode); } } catch (Exception e) { throw new MojoFailureException("Exception caught", e); } finally { if (process != null) { process.destroy(); } } }
From source file:com.ikanow.aleph2.harvest.logstash.services.LogstashHarvestService.java
/** Runs logstash in test mode before doing anything else, to check its formatting (otherwise deploying the config can crash the entire thread) * @param script// w w w. j ava 2 s . c o m * @param bucket * @param config * @param globals * @return */ protected BasicMessageBean validateLogstashConfigBeforeRunning(final String script, final DataBucketBean bucket, final LogstashBucketConfigBean config, final LogstashHarvesterConfigBean globals) { final ProcessBuilder pb = LogstashUtils.buildLogstashTest(_globals.get(), config, script, 0L, Optional.empty()); try { final Process px = pb.start(); final StringWriter outputAndError = new StringWriter(); final OutputCollectorService outAndErrorStream = new OutputCollectorService(px.getInputStream(), new PrintWriter(outputAndError)); outAndErrorStream.start(); if (!px.waitFor(60L, TimeUnit.SECONDS)) { // exited px.destroy(); } outAndErrorStream.join(); int ret_val = px.exitValue(); return ErrorUtils.buildMessage(ret_val == 0, this.getClass().getSimpleName(), "validateLogstashConfigBeforeRunning", outputAndError.toString()); } catch (Exception e) { return ErrorUtils.buildErrorMessage(this.getClass().getSimpleName(), "validateLogstashConfigBeforeRunning", ErrorUtils.getLongForm("{0}", e)); } }
From source file:com.exlibris.dps.delivery.vpp.mirador.MiradorViewerPreProcessor.java
private void setsymboliclink(String filePath) { Process p; Process pp;//w ww .j a v a 2 s.co m Process ppp; String fileDir = filePath.substring(0, filePath.lastIndexOf("/")); String filename = filePath.substring(fileDir.length() + 1); String totalfiledir = iipservDir + fileDir; String totalfilename = totalfiledir + "/" + filename; try { p = Runtime.getRuntime().exec("mkdir -p " + totalfiledir); p.waitFor(); p.destroy(); } catch (Exception e) { logger.error(e.getMessage()); } // File newDirectory = new File(totalfiledir); // if (!newDirectory.exists() || !newDirectory.isDirectory()) { // logger.error(totalfiledir+ " bestaat niet."); // } else { // ProcessBuilder pb = new ProcessBuilder("cd"); // pb.directory(newDirectory); try { // ppp = pb.start(); // ppp.waitFor(); pp = Runtime.getRuntime().exec("ln -nfs " + filePath + " " + totalfilename); pp.waitFor(); logger.info("exit: " + pp.exitValue()); pp.destroy(); // ppp.destroy(); } catch (Exception e) { logger.error(e.getMessage()); } // } }
From source file:io.appium.java_client.service.local.AppiumServiceBuilder.java
@Override protected File findDefaultExecutable() { validateNodeJSVersion();/*from w ww . java 2 s. c o m*/ Runtime rt = Runtime.getRuntime(); Process p; try { p = rt.exec(NODE_COMMAND_PREFIX + " node"); } catch (IOException e) { throw new RuntimeException(e); } try { OutputStream outputStream = p.getOutputStream(); PrintStream out = new PrintStream(outputStream); out.println("console.log(process.execPath);"); out.close(); return new File(getProcessOutput(p.getInputStream())); } catch (Throwable t) { throw new RuntimeException(t); } finally { p.destroy(); } }
From source file:com.delphix.appliance.host.example.client.ExampleClient.java
public void executeRemoteCommand() { // Execute remote command String[] remoteArgs = { "ls", "-l", "/" }; Process remote = remoteManager.executeCommand(remoteArgs, null, null, false, null); int exitCode; try {//from www . j a v a 2s .co m exitCode = remote.waitFor(); } catch (InterruptedException e) { throw new RuntimeException(e); } if (exitCode != 0) throw new RuntimeException("Remote command execution failed"); // Parse remote output try { InputStream remoteStdout = remote.getInputStream(); BufferedReader remoteReader = new BufferedReader(new InputStreamReader(remoteStdout, "UTF-8")); String line; while ((line = remoteReader.readLine()) != null) { System.out.println(line); } } catch (IOException e) { throw new RuntimeException(e); } remote.destroy(); }
From source file:org.noroomattheinn.utils.ThreadManager.java
private void watch(final String name, final Process p, final long timeout) { Runnable watchdog = new Runnable() { @Override//from w w w.j av a 2 s . c o m public void run() { long targetTime = System.currentTimeMillis() + timeout; while (System.currentTimeMillis() < targetTime) { if (hasExited(p)) { int exitVal = p.exitValue(); logger.info("External process completed: " + name + "(" + exitVal + ")"); return; } Utils.sleep(Math.min(5 * 1000, targetTime - System.currentTimeMillis())); } // p hasn't terminated yet! Kill it. p.destroy(); logger.warning("External process timed out - killing it: " + name); } }; launch(watchdog, String.format("Watchdog %d", wdID++)); }