Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to capture all the environment variables from shell?

Reply
Thread Tools

How to capture all the environment variables from shell?

 
 
Peng Yu
Guest
Posts: n/a
 
      07-26-2010
Hi,

R_HOME is set in my shell (bash). But os.environ doesn't have it. I'm
not sure what it does when os module is imported. But it seems that
os.environ doesn't capture all the environment variable from the
shell. Could anybody let me know what is the correct way to inherent
all the environment variables form the shell?

$ echo $R_HOME
/opt/R-2.11.1
$ cat main.py
#!/usr/bin/env python

import os

print os.environ['R_HOME']
$ ./main.py
Traceback (most recent call last):
File "./main.py", line 5, in <module>
print os.environ['R_HOME']
File "/opt/Python-2.6.5/lib/python2.6/UserDict.py", line 22, in __getitem__
raise KeyError(key)
KeyError: 'R_HOME'

--
Regards,
Peng
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: How to capture all the environment variables from shell? Tim Chase Python 3 08-10-2010 02:07 PM
70-284 Lab Environment, Need Virtual Environment brooklynbridge508@hotmail.com MCSA 4 05-02-2007 09:49 AM
Setting an environment variable from another environment variable marcwentink@hotmail.com Java 5 04-04-2007 10:39 PM
How to get all httpd environment variables in JSP/Servlet? RC Java 4 07-12-2005 08:32 PM



Advertisments