LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-07-2007, 09:35 AM   #1
hepburnenthorpe
Member
 
Registered: Jun 2006
Location: Sydney
Distribution: Gentoo + Debian
Posts: 132

Rep: Reputation: 15
Source Bash variables into Python environ.


I'm looking for a way to source a bash file and get some variables defined within to appear within my python environment. Something like...

Code:
#!/usr/bin/python
import os
os.exec('source foo.sh')
env = os.environ
for i in env:
  print i + "\n",
Any ideas?
 
Old 05-07-2007, 10:57 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
In any programming language, you will have to parse the script and use the system functions (typically named something like putenv() & getenv() ) to manipulate environment variables. Any attempt to run a child shell that executes or sources the script will fail, because the child's shell is wholely independent of the parent (your program). Sorry I can't give Python-specific methods to help you.

--- rod.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
python problem - compiled from source - python -V still showing old version txm123 Linux - Newbie 1 02-15-2006 11:05 AM
variables in bash haddad Linux - General 6 09-22-2004 05:29 PM
bizarre python behavior - simple cgi variables SerfurJ Programming 2 04-14-2004 02:58 PM
Setting environ. variables before bash starts at login Bralkein Linux - Software 1 03-02-2004 05:39 PM
Using letters/strings to assign variables in python Colonel Panic Programming 0 09-14-2001 10:13 PM


All times are GMT -5. The time now is 04:42 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration