List of usage examples for java.lang Process getInputStream
public abstract InputStream getInputStream();
From source file:Main.java
public static List<String> listAvailableIosPlatformVersions() { List<String> results = new ArrayList<String>(); try {/*from w w w .j ava 2 s. c o m*/ ProcessBuilder pb = new ProcessBuilder("xcodebuild", "-showsdks"); pb.redirectErrorStream(true); Process p = pb.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; Pattern pattern = Pattern.compile("-sdk iphoneos(([0-9]+.?)+)"); while ((line = reader.readLine()) != null) { Matcher m = pattern.matcher(line); while (m.find()) { results.add(m.group(1)); } } } catch (Throwable t) { } return results; }
From source file:Main.java
public static String getSystemProperty(String propName) { String line = ""; BufferedReader input = null;//from w w w .j a v a 2s. com try { Process p = Runtime.getRuntime().exec("getprop " + propName); input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024); line = input.readLine(); input.close(); } catch (IOException ex) { //Log.e(TAG, "Unable to read sysprop " + propName, ex); } finally { if (input != null) { try { input.close(); } catch (IOException e) { // Log.e(TAG, "Exception while closing InputStream", e); } } } return line; }
From source file:Main.java
public static String getSystemProp(String key) { String line = ""; try {/*from www.j ava 2 s. co m*/ Process ifc = Runtime.getRuntime().exec("getprop " + key); BufferedReader bis = new BufferedReader(new InputStreamReader(ifc.getInputStream())); line = bis.readLine(); ifc.destroy(); } catch (java.io.IOException e) { return new String(LOGTAG); } return line; }
From source file:Main.java
public static boolean isMIUI() { String propName = "ro.miui.ui.version.name"; String line;//from w w w .jav a2 s.com BufferedReader input = null; try { Process p = Runtime.getRuntime().exec("getprop " + propName); input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024); line = input.readLine(); input.close(); } catch (IOException ex) { return false; } finally { if (input != null) { try { input.close(); } catch (IOException e) { } } } return line != null && line.length() > 0; }
From source file:Main.java
public static String executeShellCommand(String... args) { try {/*from w w w . j av a 2s .c om*/ Process process = Runtime.getRuntime().exec(args); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); StringBuilder result = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { result.append(line + "\n"); } return result.toString(); } catch (IOException ignored) { } return ""; }
From source file:Main.java
/** * Get the last 500 lines of the application logcat. * * @return the log string.//w ww . j av a 2s . co m * @throws IOException */ public static String getLogcat() throws IOException { String[] args = { "logcat", "-v", "time", "-d", "-t", "500" }; Process process = Runtime.getRuntime().exec(args); InputStreamReader input = new InputStreamReader(process.getInputStream()); BufferedReader br = new BufferedReader(input); StringBuilder log = new StringBuilder(); String line; while ((line = br.readLine()) != null) log.append(line + "\n"); br.close(); input.close(); return log.toString(); }
From source file:Main.java
public static String getSystemOutput(String paramString) { String str1 = ""; try {/*from w w w. java 2 s. c o m*/ Process localProcess = Runtime.getRuntime().exec(paramString); InputStream localInputStream = localProcess.getInputStream(); InputStreamReader localInputStreamReader = new InputStreamReader(localInputStream); BufferedReader localBufferedReader = new BufferedReader(localInputStreamReader); for (;;) { String str2 = localBufferedReader.readLine(); if (str2 == null) { break; } StringBuilder localStringBuilder1 = new StringBuilder(); str1 = str1 + str2; StringBuilder localStringBuilder2 = new StringBuilder(); str1 = str1 + "\n"; } int i = localProcess.waitFor(); PrintStream localPrintStream = System.out; StringBuilder localStringBuilder3 = new StringBuilder(); localPrintStream.println("Process exitValue: " + i); return str1; } catch (Throwable localThrowable) { for (;;) { localThrowable.printStackTrace(); } } }
From source file:Main.java
public static String getSystemProperty(String propName) { String line;/*from w w w . j av a 2 s.c o m*/ BufferedReader input = null; try { Process p = Runtime.getRuntime().exec("getprop " + propName); input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024); line = input.readLine(); input.close(); } catch (IOException ex) { Log.e(TAG, "Unable to read sysprop " + propName, ex); return null; } finally { if (input != null) { try { input.close(); } catch (IOException e) { Log.e(TAG, "Exception while closing InputStream", e); } } } return line; }
From source file:Main.java
public static long getNetSpeed() { ProcessBuilder cmd;/* w w w. j a v a2s .c o m*/ long readBytes = 0; BufferedReader rd = null; try { String[] args = { "/system/bin/cat", "/proc/net/dev" }; cmd = new ProcessBuilder(args); Process process = cmd.start(); rd = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = rd.readLine()) != null) { if (line.contains("lan0") || line.contains("eth0")) { String[] delim = line.split(":"); if (delim.length >= 2) { readBytes = parserNumber(delim[1].trim()); break; } } } rd.close(); } catch (Exception ex) { ex.printStackTrace(); } finally { if (rd != null) { try { rd.close(); } catch (IOException e) { e.printStackTrace(); } } } return readBytes; }
From source file:Main.java
public static List<String> getSDCardPaths() { List<String> list = new ArrayList<String>(); BufferedReader br = null;//from w w w .j av a 2 s . c o m try { Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec("mount"); InputStream is = proc.getInputStream(); InputStreamReader isr = new InputStreamReader(is); String line; br = new BufferedReader(isr); while ((line = br.readLine()) != null) { if (line.contains("secure")) continue; if (line.contains("asec")) continue; if (line.contains("fat")) { String columns[] = line.split(" "); if (columns != null && columns.length > 1) { list.add(columns[1]); } } else if (line.contains("fuse")) { String columns[] = line.split(" "); if (columns != null && columns.length > 1) { list.add(columns[1]); } } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { } } } return list; }