Results 1 to 3 of 3
  1. #1
    steve-ss is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Can I pass a Java variable to bash script?

    Hi everyone

    This is my first post here so first and foremost, thank you for accepting me to the forum.

    I'd like to pass a variable collected in a Java program to a bash script.

    Here is the Java:

    p.add(jName);
    p.add(lName);
    p.add(jYear);
    p.add(lYear);
    p.add(jYearGroup);
    p.add(lYearGroup);

    I then want to use bash:
    studentadd $1 $2 $3
    where
    $1 corresponds to lName
    $2 corresponds to lYear
    and
    $3 corresponds to lYearGroup

    Is this possible?
    Can I pass graphically collected Java variables to bash?
    When I click Submit, how do I then access the variables in bash?

    Cheers,
    Steve


    The complete Java (which works fine) is below.

    import java.awt.*;
    import java.awt.event.*;

    public class DataEntry {
    public static void main(String[] args) {
    Frame frm=new Frame("Add a student");
    Label lbl = new Label("You can add a student by filling in this form");
    frm.add(lbl);
    frm.setSize(350,300);
    frm.setVisible(true);
    frm.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e){
    System.exit(0);
    }
    });
    Panel p = new Panel();
    Panel p1 = new Panel();
    Label jName = new Label("Name");
    TextField lName = new TextField(20);
    Label jYear =new Label("Year");
    TextField lYear=new TextField(20);
    Label jYearGroup =new Label("Year group");
    TextField lYearGroup=new TextField(20);
    p.setLayout(new GridLayout(4,1));
    p.add(jName);
    p.add(lName);
    p.add(jYear);
    p.add(lYear);
    p.add(jYearGroup);
    p.add(lYearGroup);
    Button Submit=new Button("Submit");
    p.add(Submit);
    p1.add(p);
    frm.add(p1,BorderLayout.NORTH);
    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,846
    Rep Power
    19

    Default Re: Can I pass a Java variable to bash script?

    Please use [code] tags [/code] when posting code so it retains its formatting.
    Unformatted code is hard to read.

    You can execute another program (or in this case script) via the Runtime.exec() method.
    I would suggest reading this article as well to make sure you don't fall into one of the many traps with is, especially as you want to be sure your script runs in a bash environment.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    steve-ss is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Re: Can I pass a Java variable to bash script?

    Quote Originally Posted by Tolls View Post
    Please use [code] tags [/code] when posting code so it retains its formatting.
    Unformatted code is hard to read.

    You can execute another program (or in this case script) via the Runtime.exec() method.
    I would suggest reading this article as well to make sure you don't fall into one of the many traps with is, especially as you want to be sure your script runs in a bash environment.
    Hi
    I am so sorry for posting unformatted code.

    So when I press the submit button, where are my variables? How can I access what is written in the form? How can I pass what is entered into e.g. lName??

    Cheers,
    Steve

Similar Threads

  1. pass a variable from one object to another
    By kev670 in forum New To Java
    Replies: 3
    Last Post: 11-25-2010, 01:20 AM
  2. Replies: 2
    Last Post: 04-18-2010, 04:48 AM
  3. How to pass a variable to another frame.
    By DJCali in forum New To Java
    Replies: 10
    Last Post: 10-14-2009, 03:57 AM
  4. How pass variable from jsp to servelet
    By shiva in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 04-22-2009, 01:55 PM
  5. Using Script src with a variable file name
    By Sidders at CHEP in forum New To Java
    Replies: 6
    Last Post: 03-03-2009, 05:18 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
  •