How to access Linux Global variables using Java program -


thank assistance,

i have shell script program export value. here shell script program

#! /bin/sh export test=35 echo "echo $test" 

i have executed shell script using command ./test.sh source ./test.sh (test.sh - shell script program name) have tried print value in command prompt make sure test variable export-ed , prints test value 35. test variable exported expected.

now have piece of java access test - linux global variable. sample code follows,

import java.util.map;  public class hello {     public static void main(string[] args)         {              system.out.println(system.getproperty("test"));             system.out.println("hello world");         }     } } 

now issue when execute java program getting test value null. question doing write way access global variable java. if not how can access linux global variable java program.

use system.getenv api below

 string test = system.getenv().get("test") 

getenv return map can fetch variable. on other hand, getproperty method used system properties while starting jvm supplied using -dmyvar=value.

make sure define variable @ parent shell , not sub shell or else launch jvm script access variable using getenv if launch jvm parent shell variable exported in subshell wont available parent shell.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -