Results 1 to 6 of 6
  1. #1
    karthikm897 is offline Member
    Join Date
    Aug 2009
    Posts
    3
    Rep Power
    0

    Default Java Applet Shell script

    i tried executing shell script from java applet
    but it doesnt work as it worked for normal java which i run in a shell
    please help
    is there any way to execute a shell script from java applet
    i'm using ubuntu platform

    thanks in advance

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    How did you try-out that? Can you show your code here to us?

    Basically you need an object of Java Runtime class for run the shell script, even in UNIX systems. May you've to use waitFor() to complete the process after the shell execution. Please show what you've done, otherwise it's difficult to say more about that. Good luck.

  3. #3
    karthikm897 is offline Member
    Join Date
    Aug 2009
    Posts
    3
    Rep Power
    0

    Default

    but it dint work as it worked wen i used with another cui java program
    this snippet does execute the shell script based on the text entered in the box and save the result to a file

    Java Code:
    import java.awt.*;
    
    import java.applet.*;
    
    import java.awt.event.*;
    
    
    public class shell extends Applet implements KeyListener 
    
    {
    TextField tf1;
    Label l1,l2;
    TextArea result;
    String cmd="sh /home/karthik/shell.sh ";
    String val;
    String newcmd;
    public void init()
    
    {
    val="Text:";
    result = new TextArea(val,25,150);
    tf1= new TextField(25);
    l1= new Label("Welcome",Label.CENTER);
     l1.setBounds(40,10,100,30);
    l2= new Label("Enter Text:");
    l2.setBounds(10,10,100,30);
    add(l1);
    tf1.setText(" ");
    add(l2);
    add(tf1);
    add(new Label("\n\n"));
    add(result);
    tf1.addKeyListener(this);
    }
    
    public void keyTyped(KeyEvent ke) {   
    
    }
    
    public void keyPressed(KeyEvent ke) { }
    public void keyReleased(KeyEvent ke) {
    newcmd = cmd+tf1.getText();
    result.append("\n"+newcmd);
    try {
    Runtime run = Runtime.getRuntime();
    Process pr = run.exec(cmd);
    pr.waitFor();
     }
    
    catch(Exception ie){}
    }
    }
    thanks eragna can u please solve my problem..
    Last edited by karthikm897; 08-16-2009 at 07:18 PM.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Did you get any error message when you executing the application? And also are you sure that script has no mess-up at all.

  5. #5
    karthikm897 is offline Member
    Join Date
    Aug 2009
    Posts
    3
    Rep Power
    0

    Default

    i'm sure there is nothing wrong with the shell scipt
    coz i even tried executing "nautilus" instead of that shell script and it didnt work
    as it does for the CUI program

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Replies: 4
    Last Post: 06-24-2009, 07:34 AM
  2. Replies: 1
    Last Post: 02-26-2009, 08:46 AM
  3. How to generate auto shell script using java..
    By balakrishna in forum Advanced Java
    Replies: 8
    Last Post: 12-30-2008, 07:13 PM
  4. Replies: 3
    Last Post: 07-23-2008, 09:07 AM
  5. Shell Sort in Java
    By Java Tip in forum Algorithms
    Replies: 0
    Last Post: 04-15-2008, 08:44 PM

Posting Permissions

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