• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

Initialization in shell script

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22907
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you need the current machine's hostname you can also use InetAddress.getLocalHost().getHostName().
 
reply
    Bookmark Topic Watch Topic
  • New Topic