List of usage examples for java.lang Process destroy
public abstract void destroy();
From source file:hobby.wei.c.phone.Network.java
public static String DNS(int n, boolean format) { String dns = null;//from ww w . j a va2 s .co m Process process = null; LineNumberReader reader = null; try { final String CMD = "getprop net.dns" + (n <= 1 ? 1 : 2); process = Runtime.getRuntime().exec(CMD); reader = new LineNumberReader(new InputStreamReader(process.getInputStream())); String line = null; while ((line = reader.readLine()) != null) { dns = line.trim(); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (reader != null) reader.close(); if (process != null) process.destroy(); //?? } catch (IOException e) { e.printStackTrace(); } } return format ? (dns != null ? dns.replace('.', '_') : dns) : dns; }
From source file:com.vaadin.addon.charts.util.SVGGenerator.java
protected static Process startPhantomJS() { try {/*from w w w. java 2 s . c o m*/ ArrayList<String> commands = new ArrayList<String>(); commands.add(PHANTOM_EXEC); // comment out for debugging // commands.add("--remote-debugger-port=9001"); ensureTemporaryFiles(); commands.add(JS_CONVERTER.getAbsolutePath()); commands.add("-jsstuff"); commands.add(JS_STUFF.getAbsolutePath()); final Process process = new ProcessBuilder(commands).start(); final BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(process.getInputStream())); String readLine = bufferedReader.readLine(); if (!readLine.contains("ready")) { throw new RuntimeException("PHANTOM JS NOT READY"); } Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { super.run(); if (process != null) { System.out.println("Shutting down PhantomJS instance"); process.destroy(); } } }); return process; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.mqm.frame.util.license.CollectMacAddress.java
/** * Mac?//from ww w. ja v a 2 s .co m * * @return Mac? */ public static List<String> getMacAddress() { List<String> macAddressList = new ArrayList<String>(); String os = InternationalizationUtil.toLowerCase(System.getProperty("os.name")); if (os != null && os.startsWith("windows")) { BufferedReader br = null; Process p = null; try { String command = "cmd.exe /c ipconfig /all"; p = Runtime.getRuntime().exec(command); br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = br.readLine()) != null) { if (line.indexOf("Physical Address") > 0) { int index = line.indexOf(":"); index += 2; macAddressList.add(line.substring(index).trim()); } } return macAddressList; } catch (Exception e) { log.info("", e); } finally { if (br != null) { try { br.close(); } catch (IOException e) { log.error("", e); } } if (p != null) { //? p.destroy(); } } } return macAddressList; }
From source file:org.artofsolving.jodconverter.office.ExternalOfficeManagerTest.java
public void executeTask() throws Exception { UnoUrl unoUrl = UnoUrlUtils.socket(2002); OfficeProcess officeProcess = new OfficeProcess(OfficeUtils.getDefaultOfficeHome(), unoUrl, null, null, new File(System.getProperty("java.io.tmpdir")), new PureJavaProcessManager(), true); officeProcess.start();// w w w . j a v a2 s . co m Thread.sleep(2000); Integer exitCode = officeProcess.getExitCode(); if (exitCode != null && exitCode.equals(Integer.valueOf(81))) { officeProcess.start(true); Thread.sleep(2000); } ExternalOfficeManager manager = new ExternalOfficeManager(unoUrl, true); manager.start(); MockOfficeTask task = new MockOfficeTask(); manager.execute(task); assertTrue(task.isCompleted()); manager.stop(); //TODO replace when OfficeProcess has a forciblyTerminate() Process process = (Process) FieldUtils.readDeclaredField(officeProcess, "process", true); process.destroy(); }
From source file:controllerTas.actions.gnuplot.GnuplotExec.java
public void exec() throws GnuplotException { try {//from w w w .j a v a2s .c o m Process p = Runtime.getRuntime().exec(execCommand); checkForError(p); p.destroy(); } catch (Exception e) { throw new GnuplotException(e.getMessage()); } }
From source file:com.noshufou.android.su.util.Util.java
public static String ensureSuTools(Context context) { File suTools = context.getFileStreamPath("sutools"); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); int sutoolsVersion = prefs.getInt("sutoolsVersion", 0); PackageManager pm = context.getPackageManager(); int appVersionCode; try {//from www . ja va 2s . c o m PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0); appVersionCode = info.versionCode; } catch (NameNotFoundException e) { appVersionCode = 0; } if (suTools.exists() && appVersionCode == sutoolsVersion) { return suTools.getAbsolutePath(); } Log.d(TAG, "extracting sutools"); try { copyFromAssets(context, "sutools-" + Build.CPU_ABI.split("-")[0], "sutools"); } catch (IOException e) { Log.e(TAG, "Could not extract sutools"); return null; } Process process; try { process = new ProcessBuilder().command("chmod", "700", suTools.getAbsolutePath()) .redirectErrorStream(true).start(); process.waitFor(); process.destroy(); } catch (IOException e) { Log.e(TAG, "Failed to set filemode of sutools"); return null; } catch (InterruptedException e) { Log.w(TAG, "process interrupted"); } prefs.edit().putInt("sutoolsVersion", appVersionCode).commit(); return suTools.getAbsolutePath(); }
From source file:Main.java
public static String executeCommand(String[] args) { String result = new String(); ProcessBuilder processBuilder = new ProcessBuilder(args); Process process = null; InputStream errIs = null;//from w ww .j a va 2 s. com InputStream inIs = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int read = -1; process = processBuilder.start(); errIs = process.getErrorStream(); while ((read = errIs.read()) != -1) { baos.write(read); } baos.write('\n'); inIs = process.getInputStream(); while ((read = inIs.read()) != -1) { baos.write(read); } byte[] data = baos.toByteArray(); result = new String(data); } catch (Exception e) { Log.e(TAG, e.getMessage(), e); } finally { try { if (errIs != null) { errIs.close(); } if (inIs != null) { inIs.close(); } } catch (IOException e) { Log.e(TAG, e.getMessage(), e); } if (process != null) { process.destroy(); } } return result; }
From source file:org.apache.syncope.fit.cli.CLIITCase.java
@BeforeAll public static void install() { Properties props = new Properties(); Process process = null; try (InputStream propStream = CLIITCase.class.getResourceAsStream("/cli-test.properties")) { props.load(propStream);/* w w w . j av a 2 s .com*/ File workDir = new File(props.getProperty("cli-work.dir")); PROCESS_BUILDER = new ProcessBuilder().directory(workDir); PROCESS_BUILDER.command(getCommand(new InstallCommand().getClass().getAnnotation(Command.class).name(), InstallCommand.Options.SETUP_DEBUG.getOptionName())); process = PROCESS_BUILDER.start(); process.waitFor(); File cliPropertiesFile = new File(workDir + File.separator + "cli.properties"); assertTrue(cliPropertiesFile.exists()); } catch (IOException | InterruptedException e) { fail(e.getMessage()); } finally { if (process != null) { process.destroy(); } } }
From source file:com.thoughtworks.go.helper.SvnRemoteRepository.java
public void stop() throws Exception { if (processWrapper != null) { Process process = (Process) ReflectionUtil.getField(processWrapper, "process"); process.destroy(); processWrapper.waitForExit();/*from www . j ava2 s.co m*/ processWrapper = null; } }
From source file:cz.cas.lib.proarc.common.process.AsyncProcess.java
public void kill() { Level level = isDone() ? Level.FINE : Level.WARNING; LOG.log(level, "Kill isDone: " + isDone() + ", " + cmdLine); Process process = refProcess.getAndSet(null); if (process != null) { process.destroy(); IOUtils.closeQuietly(process.getInputStream()); IOUtils.closeQuietly(process.getErrorStream()); IOUtils.closeQuietly(process.getOutputStream()); done.set(true);/* w w w . j a v a 2 s .c om*/ try { outputConsumer.join(); } catch (InterruptedException ex) { LOG.log(Level.SEVERE, null, ex); } } }