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);
}
}
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.
Re: Can I pass a Java variable to bash script?
Quote:
Originally Posted by
Tolls
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