JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

Program: How to get process environment variables in java at runtime?


Description:

The ProcessBuilder.environment() method returns you the ProcessBuilder's environemnt. Below example shows how to read it.


Code:
package com.java2novice.processbuilder;

import java.util.Map;
import java.util.Set;

public class MyEnvDetails {

	public static void main(String a[]){
		
		ProcessBuilder pb = new ProcessBuilder();
		Map<String, String> envMap = pb.environment();
		Set<String> keys = envMap.keySet();
		for(String key:keys){
			System.out.println(key+" ==> "+envMap.get(key));
		}
	}
}

Output:
SHELL ==> /bin/bash
JAVA_MAIN_CLASS_37131 ==> com.java2novice.processbuilder.MyEnvDetails
APP_ICON_385 ==> ../Resources/Eclipse.icns
com.apple.java.jvmMode ==> client
TMPDIR ==> /var/folders/2n/yf7x2fdx3bv6g31hn4stv1y0_qsrzm/T/
__CF_USER_TEXT_ENCODING ==> 0x157CE3F4:0:0
PATH ==> /usr/bin:/bin:/usr/sbin:/sbin
COMMAND_MODE ==> unix2003
DISPLAY ==> /tmp/launch-DwnV41/org.x:0
USER ==> root
com.apple.java.jvmTask ==> JNI.java
JAVA_STARTED_ON_FIRST_THREAD_385 ==> 1
Apple_Ubiquity_Message ==> /tmp/launch-u3pr6e/Apple_Ubiquity_Message
LOGNAME ==> root
Apple_PubSub_Socket_Render ==> /tmp/launch-nboOhX/Render
<< Previous Program | Next Program >>

List Of All ProcessBuilder Class Sample Programs:

  1. How to invoke other applicatons in java?
  2. How to run operating system specific command and read its output?
  3. How to get process environment variables in java at runtime?
  4. How to run ProcessBuilder with list of commands?
Knowledge Centre
Preemptive scheduling Vs Time slicing?
Preemptive scheduling: The highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence.

Time slicing: A task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.
Famous Quotations
When I do good, I feel good; when I do bad, I feel bad, and that is my religion.
-- Abraham Lincoln

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2022 by Nataraja Gootooru. All Rights Reserved.