Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package proc;
- import java.io.*;
- import java.util.stream.Stream;
- import java.text.*;
- import java.lang.ProcessBuilder;
- public class prog {
- public static void main(String args[]) throws Exception {
- try
- {
- Process process = Runtime.getRuntime().exec("ps -A ");
- BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
- BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
- // read the output from the command
- String s = null;
- while ((s = stdInput.readLine()) != null)
- {
- System.out.println(s);
- }
- // read any errors from the attempted command
- while ((s = stdError.readLine()) != null)
- {
- System.out.println(s);
- }
- }
- catch(IOException ex)
- {
- ex.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement