473,799 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9860
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@maximilli an ~ : echo $SHELL
/bin/bash
Paddy@maximilli an ~ : unset foo
Paddy@maximilli an ~ : eval `python -c 'print "foo=Hello;expo rt foo"'`
Paddy@maximilli an ~ : echo $foo
Hello
Paddy@maximilli an ~ :

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
2229
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 pick up the environment variables but am having trouble getting it done. Suppose the script is called setprod. How can I call this from inside a python script then pick up the env's later in my program? I've tried os.system ('setprod') and...
3
2970
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 having any luck so far. Here's what I've tried: ------------ #!/usr/bin/python
6
3803
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`` package there is a ``GetEnvironmentVariable``
6
4316
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 am doing it on a simple c++ program and retieving it by using getenv() function. Can anyone help me in getting the solution how to set an env variable in db2 zeeshan
1
6510
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" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
8
10096
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? -- Jack Vamvas ___________________________________ The latest IT jobs - www.ITjobfeed.com <a href="http://www.itjobfeed.com">UK IT Jobs</a>
5
3478
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
2497
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 Tommy Nordgren tommy.nordgren@comhem.se
2
2169
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 script using: import os os.setegid os.setgid
2
2148
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 Files\Symantec\pcAnywhere\;" I want to add some folders to the path and delete some. But when i read the path all the system variables "ex. "%SystemRoot%\" are converted to the exact folder I store this in a string and change the string an then write...
0
9686
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
10475
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
10250
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...
0
10026
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...
0
9068
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
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
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
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
3757
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.