how to redirect terminal contents to a jtextpane?
- by sonu thomas
hi..
I was trying to run a java class file using java code.The aim was to direct the executing sequence of the terminal of fedora 10 into a frame with a textpane.
My code is:
import java.io.DataInputStream;
import java.io.IOException;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
//import sun.reflect.ReflectionFactory.GetReflectionFactoryAction;
public class file {
/**
* @param args
*/
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
JDialog jj = new JDialog();
jj.setTitle("helllo");
String sssub1,sssub2,sssub3;
String ss="C:/Users/sonu/Desktop/ourIDE/src/src/nn.java";
JPanel n = new JPanel();
jj.setContentPane(n);
JTextPane tpn2=new JTextPane();
jj.getContentPane().add(tpn2);
jj.setVisible(true);
Runtime runtime;
Process process;
if(ss.indexOf(" ")==-1)
{
try
{
runtime= Runtime.getRuntime();
sssub1="/home/ss/Desktop/src/";
sssub2="nn";
process=runtime.exec("sh jrun.sh "+sssub1+" "+sssub2);
DataInputStream data=new DataInputStream(process.getInputStream());
DataInputStream data_data=new DataInputStream(process.getErrorStream());
String s="",t="";
int ch;
while((ch=data.read())!=-1){
s=s+(char)ch;
}
data.close();
while((ch=data_data.read())!=-1){
t=t+(char)ch;
}
data_data.close();
if(t.equals(""))
{
s+="\nNormal Termination.";
tpn2.setText(s);
}
else
tpn2.setText(t);
}catch(Exception e){
System.out.println("Error executing file==>"+e);}
}
}
}
The content of **jrun.sh** is
cd $1
java $2
When the content of **nn.java** was this:
import java.io.*;
class nn
{
public static void main(String[] ar)throws IOException
{
int i=90;
BufferedReader dt = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter");
//i=Integer.parseInt(dt.readLine()); line--notable
System.out.println("i="+i);
}
}
It worked smoothly
But when I remove the comment on line--notable,it gave me Textpane with no content.
The problem is :
I cant read an input from nn.java
Kindly give me a solution...
If i am able to:
get the terminal pop up with executing the nn.class,and i am able to enter the input,then it will do...
Thanks in advance...