Solved

Execute a unix 'ps' command in Java

Posted on 1997-12-21
2
592 Views
Last Modified: 2006-11-17
How can I execute a unix 'ps' command in unix with Java ?
0
Comment
Question by:templer122197
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
configure dependency in POM for new database 3 34
jsp insert to database example 2 46
servlet and mdb, jms error 1 33
running on tomcat not jboss eap 7.0 3 18
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

856 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