List of usage examples for java.lang Process getInputStream
public abstract InputStream getInputStream();
From source file:Main.java
public static String runCommand(String command) { try {//from w w w. j a v a 2 s.c o m StringBuffer output = new StringBuffer(); Process p = Runtime.getRuntime().exec(command); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { output.append(line + "\n"); } reader.close(); p.waitFor(); return output.toString(); } catch (InterruptedException | IOException e) { logError(e); } return ""; }
From source file:com.adguard.compiler.PackageUtils.java
private static void execute(String... commands) throws IOException, InterruptedException { ProcessBuilder pb = new ProcessBuilder(commands); Process p = pb.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line;//from www. ja v a 2 s. co m while ((line = reader.readLine()) != null) { log.debug(line); } p.waitFor(); if (p.exitValue() != 0) { reader = new BufferedReader(new InputStreamReader(p.getErrorStream())); while ((line = reader.readLine()) != null) { log.error(line); } throw new IOException("Command " + ArrayUtils.toString(commands) + " not success"); } }
From source file:Main.java
private static String getMacAddress() { String macSerial = null;// w w w . jav a2 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) { str = str.trim(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { if (str.charAt(i) != ':') { sb.append(str.charAt(i)); } } macSerial = sb.toString(); break; } } } catch (IOException ex) { ex.printStackTrace(); } return macSerial; }
From source file:Main.java
private static String getSystemProperty() { String line = ""; BufferedReader input = null;//from w w w .j av a 2s . com try { Process p = Runtime.getRuntime().exec("getprop"); input = new BufferedReader(new InputStreamReader(p.getInputStream()), 2048); String ret = input.readLine(); while (ret != null) { line += ret + "\n"; ret = input.readLine(); } input.close(); } catch (IOException ex) { Log.e(TAG, "Unable to read sysprop", 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 String dumpFile_spica2(String filename) { String line_spica2 = ""; try {//from w w w . j a v a2 s. c o m Process ifc_spica2 = Runtime.getRuntime().exec("cat " + filename); BufferedReader bis_spica2 = new BufferedReader(new InputStreamReader(ifc_spica2.getInputStream())); line_spica2 = bis_spica2.readLine(); ifc_spica2.destroy(); } catch (java.io.IOException e) { return new String(""); } return line_spica2; }
From source file:Main.java
private static String getAaptResult(String sdkPath, String apkPath, final Pattern pattern) { try {/*from www .j a v a2 s. co m*/ final File apkFile = new File(apkPath); final ByteArrayOutputStream aaptOutput = new ByteArrayOutputStream(); final String command = getAaptDumpBadgingCommand(sdkPath, apkFile.getName()); Process process = Runtime.getRuntime().exec(command, null, apkFile.getParentFile()); InputStream inputStream = process.getInputStream(); for (int last = inputStream.read(); last != -1; last = inputStream.read()) { aaptOutput.write(last); } String packageId = ""; final String aaptResult = aaptOutput.toString(); if (aaptResult.length() > 0) { final Matcher matcher = pattern.matcher(aaptResult); if (matcher.find()) { packageId = matcher.group(1); } } return packageId; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:edu.uci.ics.asterix.installer.test.AsterixClusterLifeCycleIT.java
public static String processOut(Process p) throws IOException { InputStream input = p.getInputStream(); return IOUtils.toString(input, StandardCharsets.UTF_8.name()); }
From source file:Main.java
public static int getPid(String tag) { Process p; try {/*from w w w.j a va 2s.co m*/ p = Runtime.getRuntime().exec("ps "); BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = bufferedReader2.readLine()) != null) { if (line.contains(tag)) { return Integer.parseInt(line.split("\\s+")[1]); } } } catch (IOException e) { e.printStackTrace(); } return -1; }
From source file:Main.java
public static List<String> getExtSDCardPaths() { List<String> paths = new ArrayList<String>(); String extFileStatus = Environment.getExternalStorageState(); File extFile = Environment.getExternalStorageDirectory(); if (extFileStatus.endsWith(Environment.MEDIA_UNMOUNTED) && extFile.exists() && extFile.isDirectory() && extFile.canWrite()) { paths.add(extFile.getAbsolutePath()); }/*from w w w . ja va2 s . c o m*/ try { // obtain executed result of command line code of 'mount', to judge // whether tfCard exists by the result Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec("mount"); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line = null; int mountPathIndex = 1; while ((line = br.readLine()) != null) { // format of sdcard file system: vfat/fuse if ((!line.contains("fat") && !line.contains("fuse") && !line.contains("storage")) || line.contains("secure") || line.contains("asec") || line.contains("firmware") || line.contains("shell") || line.contains("obb") || line.contains("legacy") || line.contains("data")) { continue; } String[] parts = line.split(" "); int length = parts.length; if (mountPathIndex >= length) { continue; } String mountPath = parts[mountPathIndex]; if (!mountPath.contains("/") || mountPath.contains("data") || mountPath.contains("Data")) { continue; } File mountRoot = new File(mountPath); if (!mountRoot.exists() || !mountRoot.isDirectory() || !mountRoot.canWrite()) { continue; } boolean equalsToPrimarySD = mountPath.equals(extFile.getAbsolutePath()); if (equalsToPrimarySD) { continue; } paths.add(mountPath); } } catch (IOException e) { Log.e(TAG, "IOException:" + e.getMessage()); } return paths; }
From source file:Main.java
public static String getSystemProperty(String propName) { String line = ""; BufferedReader input = null;/*from w ww .j av a 2 s .c o m*/ 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; }