473,769 Members | 7,355 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 2836
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
3754
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
2008
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
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
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
6675
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
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
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
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.