• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

GUI based interface for a (already developed)command prompt application

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to develop GUI based interface for a (already developed)command prompt application. Condition is "I cant touch its source code.I have to play on interface level."

The problem is:

I dont know when that command prompt appication will aks for input.So how can I provide input to command prompt based application ? when that application is waiting for input from keyborad;at that time my GUI based interface suppose to provide input to command prompt based application.


I dont really have the idea about how to go with this. Please help me to come to any solution.

Thanks in advance.

Rakesh (SCJP)
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know. You mean you have to change a myReader.readLine() call to text = textBox3.getText()?

Is that possible at all? I suspect you have been given an impossible task.
 
Rakesh Vende
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply Mr.Campbell Ritchie

Really It seems quite impossible. Well your suggestion asks for change in source code of command prompt based application that can not be done.

Rakesh(SCJP)
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This isn't impossible at all; I've done it a million times. Maybe you're thinking it's impossible because you think the GUI has to understand the prompts from the command-line program; that's not the case at all. Instead, it just has to properly react to them, and the way it does that is because you program in the correct response for every possible prompt. The first thing you need to do is create a flowchart on paper, or a state machine using a FSM notation, which represents the flow of prompts and inputs. Although you can't modify the source, hopefully you can look at it, as this will make it easy to verify that you've covered all the possibilities.

So you write a separate program to be the GUI. The GUI program uses Runtime.exec() to start the command-line program. It reads from the Process output/error streams, and write to the input stream using a set of independent threads.

Imagine you start the command-line program and it says



Your GUI program knows (because you know) that these are the options when the program starts up. So your GUI has a menu (let's say) with four commands: "Defrag", "Install Linux", "Nuke", "Quit". The handlers for these four menu items are real simple: the last one just prints "D" to the process's input stream, while the first three each print a character to the stream, then put up a modal dialog (let's say) which provides a GUI for the corresponding sub-tree of the flowchart, with all the possible input information. If the program prints results or information, then your GUI program knows when this will happen, and reads the information from the streams at the appropriate time, displaying it in the GUI.

A tool like ExpectJ is a big help in reading and reacting to the command-line program's output.
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As a programming exercise can the GUI interface just be a passthru from/to the commmandline program?
The GUI pgm starts the cmdline pgm and reads its prompt, displays that prompt in its GUI, gets the user's response and passes that back to the cmdline pgm, etc etc.
This would be a general purpose program that wouldn't need to be tailored to the cmdline program. It's only parameter would be the path to the cmdline pgm.
[ July 02, 2008: Message edited by: Norm Radder ]
 
Rakesh Vende
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply (solution) Ernest Friedman-Hill.:-)

I understood what you really want to say."sowftware application is nothing but responses generated for the events occured ." So I just have to keep the track of events fired on to application and Process's input & output stream will solve my probelm.

I will again post on same thread once I finish with this assignment (successfully :-).

Hi Mr. Norm Radder ,

At least for general purpose application. Isn't window based Application is answer to your question that has converted DOS to Window based Operating System . I think so. :-)

But for the specific application.. same question arise once agin.. that how will you keep the track of prompts,a command based application is asking for. So you need a different different GUI applications for different different applications .

Well but I still have a doubt in my mind.. would the "general purpose program " will help .

Rakesh (SCJP)
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was mistaken. Sorry.

I think you will have to write a tiny application and use Runtime.exec() to start it from a GUI.
Remember you have to "drain" both streams which accompany the Process created by Runtime.exec(). There have been several threads about that in the last two weeks; this is just one of many threads you can find with search.
 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic