Setting environment variables

S

Sami Viitanen

Hello,

Is there any other way to set variables than os.putenv().

Putenv doesn't actually put any values to actual system variables..

I'm trying to set CVSEDITOR variable automatically from script
so that user wouldn't have to set that him/herself. CVS can't use variable
set with putenv().


Thanks in advance.
 
E

Erik Max Francis

Sami said:
Is there any other way to set variables than os.putenv().

Putenv doesn't actually put any values to actual system variables..

I'm trying to set CVSEDITOR variable automatically from script
so that user wouldn't have to set that him/herself. CVS can't use
variable
set with putenv().

Yep, and this is a feature, at least in Unix operating systems.
Subshells cannot directly affect the operating environment of parent
shells, and shouldn't try. (One can do such things indirectly, but they
require the cooperation of the parent shell, such as sourcing the output
of a program, which is not an uncommon approach to the problem.) I
don't know if there's any way for Windows applications to affect parent
environments, but I doubt it.
 
P

Peter Hansen

Erik said:
Yep, and this is a feature, at least in Unix operating systems.
Subshells cannot directly affect the operating environment of parent
shells, and shouldn't try. (One can do such things indirectly, but they
require the cooperation of the parent shell, such as sourcing the output
of a program, which is not an uncommon approach to the problem.) I
don't know if there's any way for Windows applications to affect parent
environments, but I doubt it.

Short of bizarre hacks that are generally unacceptable, no there's no
way to do it even under Windows.

Under both operating systems, the best approach is to contrive a way
for another script to be executed *after* the application runs. That
other script either accesses data that is generated by the application,
or is actually itself generated by the application as needed, and because
it's a script (e.g. .BAT or .CMD for Windows, .sh etc. for Unix) it
is able to change the shell. (And I know you already knew this, EMF,
I was of course responding for others. :)

-Peter
 
D

David C. Fox

Erik said:
Sami Viitanen wrote:




Yep, and this is a feature, at least in Unix operating systems.
Subshells cannot directly affect the operating environment of parent
shells, and shouldn't try. (One can do such things indirectly, but they
require the cooperation of the parent shell, such as sourcing the output
of a program, which is not an uncommon approach to the problem.) I
don't know if there's any way for Windows applications to affect parent
environments, but I doubt it.

In [t]csh:

alias cvsscript "setenv CVSEDITOR `python myscript.py`"
cvsscript

or miscellaneous variants in other shells. Of course, you can't use
cvsscript from within another subshell, or it will only set the variable
in that subshell.

David
 
D

Donald 'Paddy' McCarthy

Sami said:
Hello,

Is there any other way to set variables than os.putenv().

Putenv doesn't actually put any values to actual system variables..

I'm trying to set CVSEDITOR variable automatically from script
so that user wouldn't have to set that him/herself. CVS can't use variable
set with putenv().

You could do the equivalent of:
Paddy@maximillian ~ : echo $SHELL
/bin/bash
Paddy@maximillian ~ : unset foo
Paddy@maximillian ~ : eval `python -c 'print "foo=Hello;export foo"'`
Paddy@maximillian ~ : echo $foo
Hello
Paddy@maximillian ~ :

I use the following for setting up quite complex environments at work:
http://modules.sourceforge.net/

Pad.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top