aspose file tools*
The moose likes Java in General and the fly likes Initialization in shell script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Initialization in shell script" Watch "Initialization in shell script" New topic

Initialization in shell script

Natraj Aggas

Joined: Jul 11, 2011
Posts: 15
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.

Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1112

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

Joined: Oct 27, 2005
Posts: 19794

If you need the current machine's hostname you can also use InetAddress.getLocalHost().getHostName().

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Initialization in shell script