?
Solved

Execute a unix 'ps' command in Java

Posted on 1997-12-21
2
Medium Priority
?
617 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 600 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 22 hours left to enroll

850 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