Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. package proc;
  2.  
  3. import java.io.*;
  4. import java.util.stream.Stream;
  5. import java.text.*;
  6. import java.lang.ProcessBuilder;
  7.  
  8. public class prog {
  9.  
  10. public static void main(String args[]) throws Exception {
  11. try
  12. {
  13. Process process = Runtime.getRuntime().exec("ps -A ");
  14.  
  15. BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
  16.  
  17. BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
  18.  
  19. // read the output from the command
  20.  
  21. String s = null;
  22. while ((s = stdInput.readLine()) != null)
  23. {
  24. System.out.println(s);
  25. }
  26. // read any errors from the attempted command
  27.  
  28.  
  29. while ((s = stdError.readLine()) != null)
  30. {
  31. System.out.println(s);
  32. }
  33. }
  34.  
  35. catch(IOException ex)
  36. {
  37. ex.printStackTrace();
  38. }
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement