473,757 Members | 3,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

programmaticall y manipulation environment variables of the callingshell

Hello list,

I'm trying to write a python script that would allow me to manipulate
shell variables of the calling shell. I'm trying to write some logic
that would know to add LD_LIBRARY_PATH to the users environment.

In bash this is done with "export", can I do this with python? (If at
all possible because python is actually a sub process of bash).

Thank you,
Maxim.

--
Cheers,
Maxim Veksler

"Free as in Freedom" - Do u GNU ?
Mar 12 '07 #1
5 2834
Maxim Veksler wrote:
Hello list,

I'm trying to write a python script that would allow me to manipulate
shell variables of the calling shell. I'm trying to write some logic
that would know to add LD_LIBRARY_PATH to the users environment.

In bash this is done with "export", can I do this with python? (If at
all possible because python is actually a sub process of bash).
It's not possible, OS restrictions - you are not allowed to alter the
environment of a parent process.

Diez
Mar 12 '07 #2
On Mar 12, 11:33 am, "Maxim Veksler" <hq4e...@gmail. comwrote:
Hello list,

I'm trying to write a python script that would allow me to manipulate
shell variables of the calling shell. I'm trying to write some logic
that would know to add LD_LIBRARY_PATH to the users environment.

In bash this is done with "export", can I do this with python? (If at
all possible because python is actually a sub process of bash).
The Popen class from the subprocess module takes an optional 'env'
parameter, which defines environment variables for the child process
created by Popen, if that helps.

Gerard
Mar 12 '07 #3
Hello,

On Mon, Mar 12, 2007 at 11:40:11AM +0100, Diez B. Roggisch wrote:
Maxim Veksler wrote:
I'm trying to write a python script that would allow me to manipulate
shell variables of the calling shell. I'm trying to write some logic
that would know to add LD_LIBRARY_PATH to the users environment.
It's not possible, OS restrictions - you are not allowed to alter the
environment of a parent process.
Actually, you are able to modify only your own environment (and call a
new process with any possible environment). And the restrictions seem to
me rather technical - the process would have to change its behaviour
each time it changes.

With regards

--
grep me no patterns and I'll tell you no lines.

Michal 'vorner' Vaner

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.3 (GNU/Linux)

iD8DBQBF9TG+7/oWwynB3bIRAt2xA J99VglXt7xFFqRh bo1DTPLvNYdaUAC cCH5M
kZ1RRYyLO5UtPAl BdAARNU4=
=f68I
-----END PGP SIGNATURE-----

Mar 12 '07 #4
Michal 'vorner' Vaner wrote:
Hello,

On Mon, Mar 12, 2007 at 11:40:11AM +0100, Diez B. Roggisch wrote:
>Maxim Veksler wrote:
I'm trying to write a python script that would allow me to manipulate
shell variables of the calling shell. I'm trying to write some logic
that would know to add LD_LIBRARY_PATH to the users environment.

It's not possible, OS restrictions - you are not allowed to alter the
environment of a parent process.

Actually, you are able to modify only your own environment (and call a
new process with any possible environment). And the restrictions seem to
me rather technical - the process would have to change its behaviour
each time it changes.
Not only technical - they are important security-wise - you could try and
make a parent process use a modified library that would e.g. authenticate
users without passwords.

Diez
Mar 12 '07 #5
Dennis Lee Bieber wrote:
On Mon, 12 Mar 2007 12:33:58 +0200, "Maxim Veksler" <hq*****@gmail. com>
declaimed the following in comp.lang.pytho n:
>Hello list,

I'm trying to write a python script that would allow me to manipulate
shell variables of the calling shell. I'm trying to write some logic
that would know to add LD_LIBRARY_PATH to the users environment.

In bash this is done with "export", can I do this with python? (If at
all possible because python is actually a sub process of bash).
"calling shell"... Only OS I've encountered that allowed for a form
of that was AmigaOS, which differentiated between "shell specific"
(local) environment variables:

set lev "A Local Environment Variable"

and "system-wide" (global) ones:

setenv gev "Global Stuff"

The latter statement creates a file "env:gev" with "Global Stuff" as
the contents ("env:" was a logical name for a system environment
directory -- sys:env/ where sys: was a logical for the boot drive).

As files, system environment variables could be manipulated by
almost anything...
Lacking memory protection, actually anything of anything could me
manipulated... and it was a _great_ OS, really loved it!

Diez
Mar 12 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2295
by: Robert Kern | last post by:
I'm in the middle of writing a scientific program with a number of very, very long formulae. You can see a typical one below. What I would like to do is to parse this code to yield an AST, identify identical subtrees, replace them in the AST with a dummy variable to which I will assign the common subexpression. v21c = ((1-2*nu)*((2*(1-nu)ctB*ctB-nu)*log(Ry3bar) - \ (2*(1-nu)*ctB*ctB+1-2*nu)*cB*log(Rz3bar)) - \...
4
4215
by: Bill Davidson | last post by:
All: I've found the 'Environment.GetEnvironmentVariable()' method; but how do I create and/or set an environment variable? Thanks, Bill
3
3753
by: Tristan | last post by:
Hello community: I post this because I could not find satisfactory answers in the posts generated by this nice group. I work on winXP. I have many little python applications in different folders, each application can share or not other objects located in the same or other folders. The way I work to use these applications is: 1) For almost everyone, I execute a corresponding ".bat file" into
3
2007
by: smitty1e | last post by:
Just a fun exercise to unify some of the major input methods for a script into a single dictionary. Here is the output, given a gr.conf file in the same directory with the contents stated below: smitty@localhost ~/proj/mddl4/test $ ./inputs.py {'source_db': '/home/sweet/home.db'} smitty@localhost ~/proj/mddl4/test $ source_db="test_env" ./inputs.py {'source_db': 'test_env'} smitty@localhost ~/proj/mddl4/test $ ./inputs.py -f "test_cli"
0
9297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9904
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7285
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6556
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3828
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2697
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.