KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am using the following code to get the details of all process running in the system: Process p = Runtime.getRuntime().exec("ps aux"); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); I want to filter ps aux down with the pipe symbol so I use this: Process p = Runtime.getRuntime().exec("ps aux | grep java"); It goes to the ErrorStream. Later I noticed the Pipe Symbol (|) is used as Bitwise inclusive OR operator in Java. So I used backslash in front of pipe symbol as shown below: Process p = Runtime.getRuntime().exec("ps aux \\| grep java"); But again it goes to the ErrorStream. How can I run ps aux | grep java through exec in Java?
Tags (comma-separated)
Save Edits
Cancel