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.

   
jhughes4Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DrWarezzCommented:
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]
0
DrWarezzCommented:
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]
0
jhughes4Author Commented:
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.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

Let me know.

[r.D]
0
jhughes4Author Commented:
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.



0
jhughes4Author Commented:
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());
}
0
DrWarezzCommented:
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]
0
DrWarezzCommented:
Here, I haven't tried it, but give it a go, and let me know if it's what you're after:

//-----8<---------------------------------- CommandGui.java -------------------------------------------------
import java.io.*;
import javax.swing.*;
import java.awt.*;

public class CommandGui extends JFrame {
   
    public CommandGui () {
       
        super( "GUI Title" );
        setBounds( 100, 100, 200, 90 );
        setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
       
        JLabel jl_status = new JLabel ( "" );
       
        JPanel pane = new JPanel();
        pane.add ( jl_status );
       
        setContentPane( pane );
       
        BufferedReader stdin = new BufferedReader( new InputStreamReader( System.in ) );
       
        for ( ;; ) {   // Infinite loop..
           
            try {
                String input = stdin.readLine();
               
                // Assign string to Label (in the GUI):
                jl_status.setText( input );
            } catch (Exception e) {
                e.printStackTrace();
            }
           
        }
       
    }
   
    public static void main ( String [] args ) {
        new CommandGui();
    }
   
}
//-----8<---------------------------------- CommandGui.java -------------------------------------------------

gL,
[r.D]
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jhughes4Author Commented:
Thanks!
0
jhughes4Author Commented:
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

0
DrWarezzCommented:
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]
0
DrWarezzCommented:
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]
0
jhughes4Author Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.