Solved

displaying UNIX stdout in JAVA GUI

Posted on 2002-06-24
4
278 Views
Last Modified: 2012-05-04
I have a a simple GUI with
1. TEXT AREA
2. BUTTON

when I push the button, the program runs a simple UNIX command (for example, "who" or "ls")
I need to echo the results of that command to the text area.

I don't want to do this by redirection to a file ("ls > outputfile") and then opening the file for the textarea.

I want to do this in real time, if possible (For example, if the unix command is a long "grep", then the results would scroll on the text area.

is this possible to do???

By the way, I am using JAVA NATIVE to run the unix commands ('C' system call)
0
Comment
Question by:happyloman
4 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 7104564
Careful - you've posted this several times!

import java.io.*;
public class Exec {
  public Exec(String cmdline) {
    try {
     String line;
     Process p = Runtime.getRuntime().exec(cmdline);
     BufferedReader input =
       new BufferedReader
         (new InputStreamReader(p.getInputStream()));
     while ((line = input.readLine()) != null) {
       System.out.println(line);
       // append to your TextArea here
       }
     input.close();
     }
    catch (Exception err) {
     err.printStackTrace();
     }
   }

public static void main(String argv[]) {
  new Exec("ls -l");
  }
}
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7104794
Duplicate Question Experts please post comments here:
http://www.experts-exchange.com/java/Q_20315518.html

Happyloman: Please delete this question.

Thanx,
CJ
0
 
LVL 9

Expert Comment

by:Ovi
ID: 7106677
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7109289
You posted this same question 11 times, and all have been closed.  Those which contained help to you we can leave, but others which were experts trying to alert you of the multiple entries, I'll refund for you.  Please use the "reload" button versus your Browser control buttons, and also don't hit submit more than once when creating a question.  

If you need help, any time, post a zero point question here:
http://www.experts-exchange.com/commspt/
Include the question link (URL)

Thank you,
Moondancer - EE Moderator
0

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

Join & Write a Comment

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

747 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

8 Experts available now in Live!

Get 1:1 Help Now