Solved

Execute a unix 'ps' command in Java

Posted on 1997-12-21
2
605 Views
Last Modified: 2006-11-17
How can I execute a unix 'ps' command in unix with Java ?
0
Comment
Question by:templer122197
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
ashishkh earned 150 total points
ID: 1231780
public class TestPs
{
        public static void main(String args[])
        {
          try
          {
                Runtime rt = Runtime.getRuntime();
                Process ps = rt.exec("ps");
                ps.waitFor();
                System.out.println("The output of process is " + ps.getOutputStr
eam());
                System.out.println("The output of process is " + ps.exitValue())
;
           }
           catch(Exception e)
           {
                System.err.println(e.getMessage());
           }
        }

}

The above java code executes unix 'ps' command and prints its exit value. I am printing the output of ps command. You can do so by getting the OutputStream of the Process using getOutputStream method of Process class. Then you can print the output stream of that process using normal read calls.
Hope this solves the problem.
0
 

Author Comment

by:templer122197
ID: 1231781
Excellent
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question