List of usage examples for java.lang Process getInputStream
public abstract InputStream getInputStream();
From source file:Main.java
public static Map<String, String> getCPUInfo() { Map<String, String> cpuInfo = new HashMap<String, String>(); Runtime runtime = Runtime.getRuntime(); try {//from www .j a v a2 s. c o m Process process = runtime.exec("cat /proc/cpuinfo"); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = reader.readLine()) != null) { String[] strs = line.split(":"); if (strs.length == 2) { cpuInfo.put(strs[0].trim(), strs[1].trim()); } } reader.close(); } catch (IOException e) { e.printStackTrace(); } return cpuInfo; }
From source file:Main.java
public static String readSystemProperty(String name) { InputStreamReader in = null;/*from w ww.ja v a2 s . c o m*/ BufferedReader reader = null; try { Process proc = java.lang.Runtime.getRuntime().exec(new String[] { "/system/bin/getprop", name }); in = new InputStreamReader(proc.getInputStream()); reader = new BufferedReader(in); return reader.readLine(); } catch (IOException e) { return null; } finally { silentClose(in); silentClose(reader); } }
From source file:Main.java
private static int readSystemFileAsInt(final String pSystemFile) throws Exception { InputStream in = null;/* w ww. j a v a 2 s . com*/ try { final Process process = new ProcessBuilder(new String[] { "/system/bin/cat", pSystemFile }).start(); in = process.getInputStream(); final String content = readFully(in); return Integer.parseInt(content); } catch (final Exception e) { throw new Exception(e); } }
From source file:hu.bme.mit.trainbenchmark.sql.process.MySqlProcess.java
public static void run(final String command[]) throws IOException, InterruptedException { final ProcessBuilder pb = new ProcessBuilder(command); final Process p = pb.start(); p.waitFor();//w ww .j a v a 2 s.c o m final String stdOut = getInputAsString(p.getInputStream()); final String stdErr = getInputAsString(p.getErrorStream()); // System.out.println(stdOut); // System.out.println(stdErr); }
From source file:Main.java
public static String getMac() { String macAdress = null;//from ww w . j av a 2 s . c o m String str = ""; try { Process pp = Runtime.getRuntime().exec("cat /sys/class/net/wlan0/address "); InputStreamReader ir = new InputStreamReader(pp.getInputStream()); LineNumberReader input = new LineNumberReader(ir); for (; null != str;) { str = input.readLine(); if (str != null) { macAdress = str.trim(); break; } } ir.close(); input.close(); } catch (IOException ex) { ex.printStackTrace(); } return macAdress; }
From source file:Main.java
/** * Method to find the number of files from a particular folder on the device. *//* ww w . j a va 2s . c om*/ public static int findNumberOfFiles(String dFolderPath) throws InterruptedException { int numOfFiles = 0; Thread.sleep(500); try { ProcessBuilder process = new ProcessBuilder("adb", "shell", "ls", dFolderPath, "|", "wc", "-l"); Process p = process.start(); //Thread.sleep(5000); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; p.waitFor(); while ((line = br.readLine()) != null) { if (!line.equals("")) numOfFiles = Integer.parseInt(line); } } catch (Exception e) { System.out.println(e); } return numOfFiles; }
From source file:Main.java
public static void killProcess(String packageName) { String processId = ""; try {/* w w w. j a v a 2 s. c o m*/ Runtime r = Runtime.getRuntime(); Process p = r.exec("ps"); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String inline; while ((inline = br.readLine()) != null) { if (packageName != null) { if (inline.contains(packageName)) { break; } } else { Log.e("PvTorrent_proc", "packageName is null"); } } br.close(); Log.i("PvTorrent_proc", "inline" + inline); if (inline != null) { StringTokenizer processInfoTokenizer = new StringTokenizer(inline); int count = 0; while (processInfoTokenizer.hasMoreTokens()) { count++; processId = processInfoTokenizer.nextToken(); if (count == 2) { break; } } Log.i("PvTorrent_proc", "kill process : " + processId); r.exec("kill -9 " + processId); } } catch (IOException ex) { Log.e("PvTorrent_proc", "kill" + ex.getStackTrace()); } }
From source file:com.frostwire.util.VPNs.java
private static String readProcessOutput(String command, String arguments) { String result = ""; ProcessBuilder pb = new ProcessBuilder(command, arguments); pb.redirectErrorStream(true);/* w w w . j av a 2 s.c o m*/ try { Process process = pb.start(); InputStream stdout = process.getInputStream(); final BufferedReader brstdout = new BufferedReader(new InputStreamReader(stdout)); String line = null; try { StringBuilder stringBuilder = new StringBuilder(); while ((line = brstdout.readLine()) != null) { stringBuilder.append(line); } result = stringBuilder.toString(); } catch (Exception e) { } finally { IOUtils.closeQuietly(brstdout); IOUtils.closeQuietly(stdout); } } catch (Throwable e) { e.printStackTrace(); } return result; }
From source file:Main.java
/** * Writes the current app logcat to a file. * * @param filename The filename to save it as * @throws IOException//from w w w . j a va 2 s . c o m */ public static void writeLogcat(String filename) throws IOException { String[] args = { "logcat", "-v", "time", "-d" }; Process process = Runtime.getRuntime().exec(args); InputStreamReader input = new InputStreamReader(process.getInputStream()); OutputStreamWriter output = new OutputStreamWriter(new FileOutputStream(filename)); BufferedReader br = new BufferedReader(input); BufferedWriter bw = new BufferedWriter(output); String line; while ((line = br.readLine()) != null) { bw.write(line); bw.newLine(); } bw.close(); output.close(); br.close(); input.close(); }
From source file:Main.java
public static String getMac() { String result = ""; try {/* w ww . ja v a 2 s . co m*/ Process process = Runtime.getRuntime().exec("ipconfig /all"); InputStreamReader ir = new InputStreamReader(process.getInputStream()); LineNumberReader input = new LineNumberReader(ir); String line; while ((line = input.readLine()) != null) if (line.indexOf("Physical Address") > 0) { String MACAddr = line.substring(line.indexOf("-") - 2); result = MACAddr; } } catch (java.io.IOException e) { System.err.println("IOException " + e.getMessage()); } return result; }