By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,114 Members | 1,570 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,114 IT Pros & Developers. It's quick & easy.

programmatically manipulation environment variables of the callingshell

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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/oWwynB3bIRAt2xAJ99VglXt7xFFqRhbo1DTPLvNYdaUACcCH5M
kZ1RRYyLO5UtPAlBdAARNU4=
=f68I
-----END PGP SIGNATURE-----

Mar 12 '07 #4

P: n/a
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

P: n/a
Dennis Lee Bieber wrote:
On Mon, 12 Mar 2007 12:33:58 +0200, "Maxim Veksler" <hq*****@gmail.com>
declaimed the following in comp.lang.python:
>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 discussion thread is closed

Replies have been disabled for this discussion.