0

I am wanting to run a .jar file and display the output (I'm assuming I would use a rich text box) however I also want to have a text box that will allow me to send commands to the running jar file as if it were running in a command prompt window.

Either this or embedding the command prompt would be ideal. I have messed around with code and have never got it to work.

I would also like to detect certain messages that the jar file returns, for example if a certain command is ran it will display a message depending on whether or not that failed, is there a way to read everything that get returned and then have an event happen if it detects this certain string?

How To: Execute command line in C#, get STD OUT results I have been looking at things such as that, when I say I have messed around with code, I have tried the code given in these examples (changing small parts) they never worked.

To summarise: - I want to run a jar file that obviously displays it's output in a command prompt. - I want to hide the command prompt and display it's output in a rich text box. - The jar file will return string such as 'user 1 has logged in' I want to update a labels text everytime that happens.

Community
  • 1
  • 1
  • 1
    post your code. and what is exactly that is not working, along with all the errors you can see when running it. also, please specify a little more about what you are trying to do, the approach used and the desired effect (i.e: what should be your code doing and what is actually doing, so everyone can understand your needs better) – marcelog Aug 01 '11 at 18:16
  • I have amended my original post. Thanks for your quick reply. –  Aug 01 '11 at 18:25

2 Answers2

1

You should have a look at the ProcessBuilder and Process classes. They allow to run command line programs and read/write in the process streams.

Also, if your jar is known in advance, why no simply using the class as if it would be in a library and use the exposed APIs?

Snicolas
  • 37,840
  • 15
  • 114
  • 173
0

When we started learning java at school we used

String myInput = JOptionPane.showInputDialog(this, "myPrompt");

and

JOptionPane.showMessageDialog(null, "A basic JOptionPane message dialog");

for input and output. Very simple.

Or you can use the command-line:

BufferedReader br = new BufferedReader(new InputStreamReader(System.in)
String input = br.readLine();
Tommy
  • 4,011
  • 9
  • 37
  • 59