Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GUI for console i/o

Status
Not open for further replies.

pwntn

Programmer
Apr 26, 1999
3
CA
Hello Java programmers; as a new Java programmer, I am seeking some assistance, ideas, tips, code snippets etc. for the following: from a Java GUI application, I would like to (e.g.) click a button and have the application perform a command as if I was entering the command at the DOS prompt. In addition, once the command was finished executing, I would like to see the results displayed in a text window in the application.

If anyone has any suggestions, or could point me in right direction, or even provide some code snippets that do this or something similar, I would be most grateful. I have found some code examples & suggestions from other posts in Tek-Tips and the java.sun.com, so I am not completely in the dark. Many thanks in advance to those that can help!
 
RobRoy,
Why do you want to shell out to DOS ? Many of the things done in native OS can be done in java, and if you only want to work with Microsoft OS's, then it may be better to work with the Win32 API and Visual C++. Shelling out to a native OS seems to me to go against the spirit of java coding.
GUI's are easy to build with Visual C++, and work a lot quicker than Swing - which is notoriously slow. (Sorry java lovers).

Ben
 
Hi Sedj, thank you for your response. I apologize for not making myself clear in my initial post. What I am doing is creating a GUI application for a simple XML-RPC web service. At this time, I open DOS command prompt window and then run the java web service client application from the command prompt. If all goes well, I get a response back.

In a nutshell, I want to create a GUI application for purposes of communicating with XMl-RPC or SOAP web services. What I want to do is develop a Java GUI application where I can enter some parameters into one or more text fields and then (e.g.) left-click a button to execute the XML-RPC or SOAP request. I didn't mean that I would necessarily do this through a commmand prompt window; my apologies again for the confusion.

I am trying to figure how I can, from a GUI application, send commands via stdout and then (1) determine if I have received a response and (2) deal with the response when I have in fact received it.

Doing this in VB would be very easily as I have written lots of VB - Win32 API code for VB CGI applications.

I hope my intentions have been clarified here, and again, thank you in advance for your assistance.
 
Right - I think you want to look at the Remote Method Invocation (RMI) package - which deals with calling objects on, say a server, from a client - I've never done any rmi myself though and dont really know much about it.

However, as a patch (if I understand your problem correctly)if you have a server, and you want to know when a client has made a connection/called some methods etc, then it may just do to have a global variable(s) on the server-side, which, when the client calls some certain methods/performs some actions is turned on (eg boolean). You could then have a thread that sits in a while loop, waiting for this variable(s) to change status. and then fires off some other events or methods - maybe something like :

static Thread thread;
static boolean DATA_RETURNED;

///
/// other code
///

thread = new Thread(new Runnable() {
public void run() {
try {
while (!DATA_RETURNED) {
System.out.println("Waiting ! ....");
}
// fire off code methods once DATA_RETURNED is true
}
catch (InterruptedException e) { System.out.println(e.toString());
}

}
});
thread.start();


So this thread will sit there in the while loop until DATA_RETURNED becomes true - at which point it exits the loop, and executes the rest of the code - which will be the events or methods you wnat to occur once the client has connected ..
I hope this is what you are after ... if not then look into rmi !!!!

Ben



 
Hi RobRoy,
if you want to execute any OS command, call
Code:
Runtime.getRuntime().exec(c);[\code]
where c is your command string. There are other exec methods w/ different param structure, just take a look at the class Runtime documentation.
All these methods return a Process which gives you access to the output of the command and other things (like waiting for completion)

Christoph
 
hi Sedj, Christoph: thanks very much for your excellent suggestions; I appreciate your help & the time you have taken to respond. I will begin investigating the ideas you have put forward and see how I can incorporate into my project. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top