473,414 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Setting environment variables

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.
Jul 18 '05 #1
4 9841
Sami Viitanen wrote:
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.

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ Perfect situations must go wrong
\__/ Florence, _Chess_
Jul 18 '05 #2
Erik Max Francis wrote:

Sami Viitanen wrote:
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.


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
Jul 18 '05 #3
Erik Max Francis wrote:
Sami Viitanen wrote:

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.


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
Jul 18 '05 #4
Sami Viitanen wrote:
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.

Jul 18 '05 #5

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

Similar topics

3
by: Greg Lindstrom | last post by:
Hello- I am running python 2.3. on an HP-9000 box running Unix and have a POSIX script that sets up my production environment. I would like to run the script from inside a python routine and...
3
by: David Durkee | last post by:
Hi, I'm trying to write a script I can run from tcsh in Terminal (on Mac OS X) that will set environment variables that can be accessed by subsequent commands I execute in that session. Not...
6
by: Fuzzyman | last post by:
Hello all, I would like to set a Windows Environment variable for another (non-child) process. This means that the following *doesn't* work : :: os.environ = value In the ``win32api``...
6
by: shaan.shaan | last post by:
Hi I am trying to set an env. variable by exporting in unix environment on DB2. I am using export var_name=ON, but it is not taking the value of the var_name. This thing is working fine when I...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
8
by: Jack Vamvas | last post by:
I know that you can do : Request.ServerVariables("QUERY_STRING") but can you actually set a serverVariable? I know that sounds counter intuitive , but is it possible, via vbscipt/asp? -- ...
5
by: Henaro | last post by:
Hello~ I am having trouble setting environment variables in C++ on win32. The code that is not working is: char prxy; char pf_cmd1 = "set http_proxy="; ....
18
by: Tommy Nordgren | last post by:
Given the following: def outer(arg) avar = '' def inner1(arg2) # How can I set 'avar' here ? ------------------------------------- This sig is dedicated to the advancement of Nuclear Power...
2
by: Henry Hollenberg | last post by:
Hello, I have written a script that uses environment variables set during a particular users login in ".bash_profile" and ".profile". I have changed to that users uid and gid in my python...
2
by: bart.hernalsteen | last post by:
Hi, I want to read the envorinment setting "path" and then on certain conditions change this setting. ex path : "%SystemRoot%\system32;%SystemRoot%;%SystemRoot% \System32\Wbem;C:\Program...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...

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.