1. public void inputShell(String string) {
    2. try {
    3. Process process;
    4. process = Runtime.getRuntime().exec(new String[]{"/bin/sh","-c",string});
    5. process.waitFor();
    6. BufferedReader read = new BufferedReader(new InputStreamReader(process.getInputStream()));
    7. String line = null;
    8. String result = "";
    9. while ((line = read.readLine())!=null){
    10. result+=line;
    11. System.out.println(line);
    12. }
    13. System.out.println("result:"+result);
    14. } catch (IOException | InterruptedException e1) {
    15. e1.printStackTrace();
    16. }
    17. }