Example usage for java.lang Process getInputStream

List of usage examples for java.lang Process getInputStream

Introduction

In this page you can find the example usage for java.lang Process getInputStream.

Prototype

public abstract InputStream getInputStream();

Source Link

Document

Returns the input stream connected to the normal output of the process.

Usage

From source file:ch.epfl.eagle.daemon.util.Resources.java

public static int getSystemMemoryMb(Configuration conf) {
    int systemMemory = -1;
    try {/*from   ww w  .j  a va 2s  . c o m*/
        Process p = Runtime.getRuntime().exec("cat /proc/meminfo");
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line = in.readLine();
        while (line != null) {
            if (line.contains("MemTotal")) {
                String[] parts = line.split("\\s+");
                if (parts.length > 1) {
                    int memory = Integer.parseInt(parts[1]) / 1000;
                    systemMemory = memory;
                }
            }
            line = in.readLine();
        }
    } catch (IOException e) {
    }
    if (conf.containsKey(EagleConf.SYSTEM_MEMORY)) {
        return conf.getInt(EagleConf.SYSTEM_MEMORY);
    } else {
        if (systemMemory != -1) {
            return systemMemory;
        } else {
            return EagleConf.DEFAULT_SYSTEM_MEMORY;
        }
    }
}

From source file:com.sonicle.webtop.core.app.util.OSInfo.java

private static String getCmdOutput(String command) {
    String output = null;/*from   www.  j  ava2 s.  c o  m*/
    try {
        Process pro = Runtime.getRuntime().exec(command);
        BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream()));
        output = br.readLine();
        pro.waitFor();
    } catch (Throwable th) {
        /* Do nothing! */ }
    return output;
}

From source file:Main.java

/**
 * Locte the tun.ko driver on the filesystem  
 * @return a String with the path of the tun.ko driver
 *//*w w  w  .  j  av  a2s .  c  o  m*/
public static String findTunDriverPath() {
    String tunDriverPath = "";
    String find_str;
    try {
        Process find_proc = Runtime.getRuntime().exec("find /sdcard /system /data -name tun.ko");
        DataInputStream find_in = new DataInputStream(find_proc.getInputStream());
        try {
            while ((find_str = find_in.readLine()) != null) {
                tunDriverPath = find_str;
            }
        } catch (IOException e) {
            System.exit(0);
        }
    } catch (IOException e1) {
        Log.e("OpenVpnSettings_Util", e1.toString());
    }

    //      if (new File(tunDriverPath).exists())
    //         System.out.println(tunDriverPath);
    //      else System.out.println("ERROR file does not exist: " + tunDriverPath);
    return tunDriverPath;
}

From source file:citibob.licensor.MakeLauncher.java

static void exec(File dir, String... cmds) throws IOException, InterruptedException {
    Process proc = Runtime.getRuntime().exec(cmds, null, dir);
    InputStream in = proc.getInputStream();
    int c;/*  w w  w.  j  a  v a 2s . co m*/
    while ((c = in.read()) >= 0)
        System.out.write(c);
    proc.waitFor();
    System.out.println("---> exit value = " + proc.exitValue());
}

From source file:Main.java

public static String getSystemProperty() {
    String line = null;/*w  ww  . ja v  a 2s  .c om*/
    BufferedReader reader = null;
    try {
        Process p = Runtime.getRuntime().exec("getprop ro.miui.ui.version.name");
        reader = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
        line = reader.readLine();
        return line;
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (reader != null) {
                reader.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return "UNKNOWN";
}

From source file:edu.uci.ics.asterix.installer.test.AsterixClusterLifeCycleIT.java

@AfterClass
public static void tearDown() throws Exception {
    Process p = managixInvoke("delete -n vagrant-ssh");
    Assert.assertTrue(checkOutput(p.getInputStream(), "Deleted Asterix instance"));
    remoteInvoke("rm -rf /vagrant/managix-working");
    LOGGER.info("Test delete active instance PASSED");
}

From source file:com.ms.commons.standalone.utils.Shell.java

public static String exec(String cmd) {
    Process process = null;
    String[] cmds = { "/bin/bash", "-c", cmd, };
    try {//from  w w w  .  jav  a 2s  . c o m
        process = new ProcessBuilder(cmds).redirectErrorStream(true).start();
        byte[] buffer = IOUtils.toByteArray(process.getInputStream());
        process.waitFor();
        return new String(buffer, "utf-8");
    } catch (Exception e) {
        logger.error("runtime.exec cmd: " + cmd + " failed", e);
    } finally {
        if (process != null) {
            process.destroy();
        }
    }
    return "";
}

From source file:mitm.common.sms.transport.gnokii.Gnokii.java

public static String identify() throws GnokiiException {
    String[] cmd = new String[] { GNOKII_BIN, "--identify" };

    try {//from w w  w.j a v  a2 s  .c  om
        ProcessBuilder processBuilder = new ProcessBuilder(cmd);
        processBuilder.redirectErrorStream(true);

        Process process = processBuilder.start();

        String output = IOUtils.toString(process.getInputStream());

        int exitValue;

        try {
            exitValue = process.waitFor();
        } catch (InterruptedException e) {
            throw new GnokiiException("Identify error. Output: " + output);
        }

        if (exitValue != 0) {
            throw new GnokiiException("Identify error. Output: " + output);
        }

        return output;
    } catch (IOException e) {
        throw new GnokiiException(e);
    }
}

From source file:com.stratio.connector.cassandra.CCMHandler.java

/**
 * Start a test Cassandra cluster to execute the unit tests. The method creates a
 * temporal file with the contents of {@code /com/stratio/meta/test/test.sh} and proceeds
 * with its execution.//from  w  w  w .  j  a  v  a2s . com
 */
public static void startCCM() {
    BufferedReader in = null;
    try {
        File tempFile = File.createTempFile("stratio-start-ccm", ".sh");
        InputStream resourceStream = CCMHandler.class
                .getResourceAsStream("/com/stratio/connector/cassandra/test.sh");
        FileUtils.copyInputStreamToFile(resourceStream, tempFile);
        tempFile.setExecutable(true);

        Process p = Runtime.getRuntime().exec(tempFile.getAbsolutePath());

        in = new BufferedReader(new InputStreamReader(p.getInputStream(), Charset.forName("UTF-8")));

        String line;
        while ((line = in.readLine()) != null) {
            LOG.debug(line);
        }
        FileUtils.forceDeleteOnExit(tempFile);

    } catch (IOException e) {
        LOG.error("Error starting CCM", e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                LOG.error("IO exception closing ccm output.", e);
            }
        }
    }
}

From source file:Main.java

private static boolean checkRootMethod3() {
    Process process = null;
    try {// w w  w  . j a v a2s .  c  om
        process = Runtime.getRuntime().exec(new String[] { "/system/xbin/which", "su" });
        BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
        return in.readLine() != null;
    } catch (Throwable t) {
        return false;
    } finally {
        if (process != null)
            process.destroy();
    }
}