Results 1 to 3 of 3
  1. #1
    ArnOfMagnus is offline Member
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Default [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
    Java 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".

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default

    Any chance you can provide more details than that?

  3. #3
    ArnOfMagnus is offline Member
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Default

    I forgot to mention that cmdText is textfield for typing shell script, cmdResult is the textarea for showing the result.

    Does that doesnt give enough information?

Similar Threads

  1. Java - Error in terminal window
    By cvillejin in forum New To Java
    Replies: 3
    Last Post: 04-01-2011, 08:03 PM
  2. Mac Terminal
    By Java8 in forum Other IDEs
    Replies: 0
    Last Post: 01-16-2010, 06:19 PM
  3. How to create custom Input Dialog
    By Bab in forum SWT / JFace
    Replies: 2
    Last Post: 08-02-2009, 12:21 PM
  4. Create custom control
    By Omarero in forum New To Java
    Replies: 1
    Last Post: 03-24-2009, 05:50 PM
  5. Terminal
    By dj kourampies in forum New To Java
    Replies: 7
    Last Post: 01-07-2009, 03:57 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •