Solved

displaying UNIX stdout in JAVA GUI

Posted on 2002-06-24
4
310 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
[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
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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
eclipse apache tomcat admin console 52 156
tomcat startup error 5 136
by zero exception 10 70
How to determine if a string is a valid SHA value 7 44
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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

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