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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Initialization in shell script" Watch "Initialization in shell script" New topic
Author

Initialization in shell script

Natraj Aggas
Greenhorn

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

Joined: Aug 27, 2012
Posts: 1067
    
  10

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

Joined: Oct 27, 2005
Posts: 19722
    
  20

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Initialization in shell script