Use jsp pages to connect to a UNIX server

Posted on 2005-04-29
Last Modified: 2008-01-09

I need to create a solution wherein a jsp site talks to applications running on UNIX server. For starters lets say - a jsp request sent to check the status of any UNIX process by running a 'ps' command on UNIX. I would like to get the result of the 'ps' command and should be able to display the same on the web.

I am pretty new to the jsp domain - please suggest a solution ASAP and in a very basic fashion.

Any pointers to articles, tutorials, books online will also be appreciated.

Thanks in advance.

Question by:sushiltanna
    LVL 19

    Accepted Solution

    you can use System.runtime to run the process on the unix server..
    pre-requesite is that your jsp shd be running on that same server....
    code sniplett will look something like..
      String ls_str;

              Process ls_proc = Runtime.getRuntime().exec("/bin/ls -aFl");

              // get its output (your input) stream

              DataInputStream ls_in = new DataInputStream(

              try {
                while ((ls_str = ls_in.readLine()) != null) {
              } catch (IOException e) {

          } catch (IOException e1) {
    LVL 8

    Expert Comment

    One more example

              Runtime runTime = Runtime.getRuntime();
              Process process = runTime.exec ("/bin/ps");
              InputStream inputStream = process.getInputStream();
              InputStreamReader   inputStreamReader = new InputStreamReader (inputStream);
              BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
              String line = null;
             while ( (line = bufferedReader.readLine()) != null )
             int exitVal = process.waitFor();
             out.println ("Process exitValue:  " + exitVal );
              catch (Throwable t)

    In the above code bufferedReader.readLine() will read all the lines that are printed by the 'ps' command and print on the page.process.waitFor() will return the exit value of the command.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    Title # Comments Views Activity
    When Does RestAdapter establishes HttpConnection 5 176
    ajax auto save 15 89
    Display the newly inserted values 3 70
    countXY challenge 28 90
    After several days of searching and hunting for limited documentation, I wanted to share this guide to hopefully save someone the hassle of trying to figure this out on their own. I have tested this on Xendesktop 7.1 and PS 4.5 running simultaneous…
    ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now