get Shell Ouput Message Of Command - Java Native OS

Java examples for Native OS:Process

Description

get Shell Ouput Message Of Command

Demo Code


//package com.java2s;
import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static String getOuputMessageOfCommand(InputStream is) {
        String message = "";
        try {/*  ww  w .  java2  s  .  com*/
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(">>" + line);
                message += line;
            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
        return message;
    }
}

Related Tutorials