[ASK] How to create custom terminal with java app?
Hi im new in here, i got a question about how to create custom terminal with java app. Any help would be great.
My idea at first was to create a jframe form with a text field, submit button and a text area . Text field for typing shell script, submit button to submit it and process it then text area to display the result of that shell script.
Here is some of my code
Code:
private static boolean procDone(Process p)
{
try
{
int v = p.exitValue();
return true;
}
catch(Exception pr)
{
return false;
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Runtime r = Runtime.getRuntime();
// try{
// Runtime.getRuntime().exec("xterm");
// }catch(Exception io){}
String[] cmd = {"sh", "-c", cmdText.getText()};
cmdResult.setText(null);
try{
Process p = r.exec(cmd);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
System.out.println("Result from runtime is "+stdInput.readLine()+"===");
int count = 0;
String s = null;
String commandResult = "";
while(!procDone(p))
{
while((s=stdInput.readLine()) != null){
count++;
commandResult += "Line "+count+": "+s+"\n";
//System.out.println("result:"+count+" --- "+s+"\n");
}
}
stdInput.close();
cmdResult.setText(commandResult);
p.waitFor();
}
catch(Exception io)
{
io.printStackTrace();
}
}
There is some problem of my code , one of it if i use like "more bla.txt".