Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between System.getenv() & System.getProperty() [duplicate]

Possible Duplicate:
What’s the difference between a System property and environment variable

What is the difference between System.getenv() & System.getProperty()?

When we run any command using Processbuilder, we can set the environment variables ie:

String[] vCmd = { System.getenv("ANT_HOME") + "/bin/ant", "-f",                 ANT_BUILD_FILE, TARGET };         ProcessBuilder pb = new ProcessBuilder(vCmd);         Map<String, String> env = pb.environment();              env.put("CLASSPATH",                 antHome+"/lib/ant.jar:"                         + antHome+"/lib/ant-launcher.jar:"                         + antHome+"/lib/ant-nodeps.jar:"                         );         try{              Process process = pb.start();             InputStream is = process.getInputStream();             InputStreamReader isr = new InputStreamReader(is);             BufferedReader br = new BufferedReader(isr);             String line;             while ((line = br.readLine()) != null) {                 System.out.println(line);             }             pb.wait();         }         catch(Exception e)              System.out.println(e.getMessage());           } 

If I set some properties using System.setProperties() before this method , is it available to this process started by ProcessBuilder?

like image 574
user1731553 Avatar asked Oct 28 '12 19:10

user1731553


People also ask

What is use of system Getenv in Java?

On the Java platform, an application uses System.getenv to retrieve environment variable values. Without an argument, getenv returns a read-only instance of java.util.Map , where the map keys are the environment variable names, and the map values are the environment variable values.

What is difference between system property and environment variable?

System properties are specified with command-line options in Java using the -Dname=value while environment variables are set in the operating system, using the EXPORT command in Unix and SET command in windows. To get a specific system property, we can use the System.

Can system Getenv return null?

java - System. getenv() returns null when the environment variable exists - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.

How does system getProperty work in Java?

The getProperty(String key) method in Java is used to returns the system property denoted by the specified key passed as its argument.It is a method of the java. lang. System Class. where key is the name of the System property.


1 Answers

System.getenv gets an environment variable. System.getProperty gets a Java property. Environment variables are specified at the OS level. Java properties are specified by passing the -D option to the JVM (and can be set programmatically).

like image 146
T.J. Crowder Avatar answered Oct 23 '22 03:10

T.J. Crowder