0

I used java to execute bash script to count total of the process. But, the result I got is empty in input BufferedReader.

public static void main(String[] args) {
            try {
                Process process = Runtime.getRuntime().exec("ps aux | wc -l");
                BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
                String line = null;
                while ((line = stdInput.readLine()) != null) {
                    System.out.println(line);
                }
            } catch (Exception ex) {
                Logger.error(TAG, ex);
            }

but when I execute "ps aux | wc -l" in terminal it return "250". Can anyone help me. Thanks so much.

VanThaoNguyen
  • 792
  • 9
  • 20
  • I scanned the web for a while. It seems that the processing above is somehow deprecated. You're supposed to use a ProcessBuilder instead. –  Feb 12 '17 at 11:13
  • Thanks, I work with ProcessBuilder but I can't work with this situation. regard – VanThaoNguyen Feb 12 '17 at 14:01

0 Answers0