Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Initialization in shell script

 
Natraj Aggas
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to initialize variables to get mt hostname in shell script. How do I do that? I also need to pass an input param from Java to script. Help me how do I do all these.

Thanks,
-N
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you talk of a shell script then I assume you are using some version of Unix/Linux. To get the hostname in Unix/Linux you use the 'hostname' command so you can make your Java program accept command line parameters and pass the hostname as a parameter. For example
java YourProgramMainClass -hostname $(hostname)

I don't understand what you mean by "I also need to pass an input param from Java to script" . Do you mean you want to return a value or values from your Java program back to the script that invoked it? If so then write the values to the Java program 'stdout' using System.out and then read the 'stdout' inside your script.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you need the current machine's hostname you can also use InetAddress.getLocalHost().getHostName().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic