Reading from an application command line interface
Hi,
I have developed a console application which reads a file and displays some information over a period of time in a command line interface. I am invoking the application from my GUI(in Java swing) using Runtime.exec().
I need to somehow make this application CLI invisible on invoking and show the execution details on my front end. For the time being, it should be fine if I am able to display the results on the Eclipse output tab.
I am unable to read anything at all from the application CLI.
PLEASE HELP!!!!
[546 byte] By [
Daffya] at [2007-11-27 0:50:15]

# 1
> For the time being, it should be fine if I> am able to display the results on the Eclipse output> tab.As in "System.out.prinln(...);"? So do it...I don't understand the rest, though.
# 2
I am invoking my application executable using the following piece of code :
Process p = Runtime.getRuntime().exec("cmd.exe /C start Application_name.exe");
I am then trying to print the output to the executable on the Eclipse IDE console by this chunk of code :
InputStream in = p.getInputStream();
int i = in.read();
while (i != -1)
{
System.out.print((char)i);
i = in.read();
}
However, i am not getting any output on the Eclipse console even though the application is beng invoked and executed sucessfully.
Kindly tell me if there is any error in the code....
Thanx
Daffya at 2007-7-11 23:20:13 >

# 3
First change it to Runtime.getRuntime().exec("Application_name.exe") and see if it helps.
If that doesn't help, you should read this article:
(for one thing, you should really have separate threads to drain
the output from a subprocess. So that could be the problem)
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
# 4
thank you so much Kathy!!!! Your advice really paid off and my program is working just the way I need it to :)Thank you so much....
Daffya at 2007-7-11 23:20:13 >

# 5
Hi,
Now I am facing another problem :(
My GUI screen is hanging till the process invoked completes its execution and exits. Im unable to view the results on my GUI console.
This is my code :
public class MyDemo
{
public static InputStream tpIn;
public byte buff;
public MyDemo()
{
try
{
Process p = Runtime.getRuntime().exec("D:/MyFolder/Application_Name.exe");
InputStream tpIn;
int i=0;
while(i!=-1)
{
tpIn = p.getInputStream();
buff = (byte)tpIn.read();
i = buff;
System.out.print((char)buff);
(JTextArea_Field).append(new String(new byte[] { (byte)buff }));
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Here, JtextArea_Field (GUI console) is the static JTextArea in the class containing my main function.
Please tell me what is wrong in the way I am trying to update my GUI console.
Daffya at 2007-7-11 23:20:13 >

# 6
There are several things you are doing wrong.
I recommend you go through a Swing thread tutorial.
1) First of all, you are not supposed to make GUI calls
except from the "AWT Event Dispatch Thread".
But in this case, you are clearly trying to alter JTextArea content
from a regular thread. Try using a SwingWorker (see tutorial)
2) Second of all, the JTextArea changes will not "show up"
until the "AWT Event Dispatch Thread" has a chance to look at your
requests and make the corresponding changes.
http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html
# 7
Yeah, i guess I need to clear up my thread basics first.Will look through it. Thanx!
Daffya at 2007-7-11 23:20:13 >
