Link to home
Start Free TrialLog in
Avatar of jhughes4
jhughes4

asked on

command from DOS read and accepted by GUI

  Can I have a Java GUI application that receives DOS commands to initiate an action as it does with ActionEvent, ActionListener, etc.  For an example let’s say my application has been started from within a .bat file by an external application, and a GUI is launched that displays some information.  Then let’s say the external application sends a string of text to get my GUI application to initiate some other action.  1)  Is this possible? 2) What would be the best approach to capture this text from the external application?

Thanks in advance.

   
Avatar of DrWarezz
DrWarezz

I think that you can only retrieve outputted text from a batch file, if you CALL the batch file from inside your application (rather than the batch file calling your application).

I can give you some code for that if you'd still like.

gL,  :-)
[r.D]
hmm.. hold on.. I just re-read your Q.
Do you want to capture the text from the external app? If so, how do you plan to communicate with it? Have you programmed this other app yourself? If so, you can use a Socket connection, or agree on a File to transfer data via.

What is this other application, and what language has it been programmed in? Also, how do you start this external application? Is it just an .EXE ? Or a Java CLASS (/.JAR) file?

gL,
[r.D]
Avatar of jhughes4

ASKER

I have no control over the external application, it's an exe.  However, the external application can be configured with "hot keys".  For example, I can configure a button to be assigned to notepad to execute the following commands:
<ENTER>
"this is a test"
<ENTER>

so that in the notepad window the following shows up

this is a test

Does this help?

If I can't update the GUI app directly from the external application, could I create a separate application that reads args[] interactively and interacts with the GUI app without having to restart the GUI app for each command?

Thanks for the response.
So, the 'commands' are outputted to a text file? If so, that's not too hard to solve..

Let me know.

[r.D]
No sorry, the commands aren't sent to a text file.  I was only using notepad as an example.  The commands are issued directly to the application you indicate within this external application.  My preference would be to not use a file since there are two separate processes reading and writing to that file.  What I think I would like to do is to have a class file that continuously reads arguments, and based on the arguments executes or displays information in a GUI without having the GUI restart.

For example:
1)      App is started….   java StartRead  (waits on arguments sent into DOS).
2)      External app is started and enters an “s” in the DOS window.
3)      StartRead.java reads “s” and puts in a window “STARTED”.
4)      External app is started and enters an “h” in the DOS window.
5)      StartRead.java reads “h” and replaces “STARTED” with “HELP”.

If this is possible how would I continuously loop through the arguments and how would I update the window/GUI?

Thanks again.



I've been able to find out how I can continuously read the arguments see the attached code.  However, I'm still unsure as to how I can take that argument (input String) and pass it to some sort of GUI.  Thanks in advance for the help.

      try {

java.io.BufferedReader stdin = new java.io.BufferedReader( new java.io.InputStreamReader( System.in ) );

while (true)
{
      String input = stdin.readLine();

      System.out.println("HERE'S THE INPUT MESSAGE:" + input);
}
} //end of try
catch (Exception e) {
      System.out.println("THE FOLLOWING EXCEPTION OCCURRED:" + e.toString());
}
Ah k, I think I'm with you now..

So, you've assigned the outputted string (from the external app) to the variable: "input".
You then need to create a GUI, and display it, right?

I'll start coding something for you now.. If I'm mistaken though, let me know :-)  (Sorry for not getting it the first time).

gL,
[r.D]
ASKER CERTIFIED SOLUTION
Avatar of DrWarezz
DrWarezz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks!
I've been playing around with your sample and even though I've accepted your answer you can still answer a question for me.  When you run the app, the JPanel is brought up as the active window, so as a result the commands being issued won't work.  Is there a way to bring up JPanel at a certain location in the window, but in an inactive state?

thanks again

you can change the x,y location co-ordinates, like so:

setBounds ( x, y, width, height );

You can also turn it into a JWindow, like so:

Remove this line: setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
And change this line:

public class CommandGui extends JFrame {

to:

public class CommandGui extends JWindow {

Let me know if that helps,
[r.D]
And to make the window inactive, I think that this should do the trick:

After the line: "setContentPane( pane );", add this:
toBack();

I think that's the method.. let me know.
[r.D]
Thanks