Re: [Tutor] trouble setting the environment
> Is this possible? I vaguely remember something about the system env and the > interpreters env being separate after the interpreter starts up. When you execute another process it gets its own environment. When it dies its environment dies with it. You can get round this in your case by forking the child process and reading the environment variables and writing them back via a pipe to the original program - messy but it works! > >>> os.system(". envSet.ksh") > 0 > >>> os.getenv("OPSBIN") > >>> > > What is the 0. The return value from os.system(). It basically means the command ran without errors. Not too useful normally. popen() is better if you want to read the output (it basically does the fork/pipe thing automagically for you) So if you popen a script that runs your ksh file then prints the environment variables, you can read them into your program... HTH, Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
RE: [Tutor] trouble setting the environment
Kent, Like you allude ...a bit too much "what the heck is that" going on. I will give a few other things a try...I may just have to have the program run and get the info then stop and have the user source the correct .ksh then run another py program. (basically the same thing but manually). Thanks, John Ertl -Original Message- From: Kent Johnson [mailto:[EMAIL PROTECTED] Sent: Thursday, April 21, 2005 13:49 Cc: tutor@python.org Subject: Re: [Tutor] trouble setting the environment Ertl, John wrote: > Kent, > > Good idea except that the environment that needs to be set depends on the > answers to some of the input that I get in the Python program. Nothing is > ever easy here. Maybe you could write a Python program that asks the questions, then spawns a shell task which sets the correct environment and runs another Python program that does the rest of the work? Or, a ksh wrapper that sources the right program then outputs its environment to a .py file that you can import to get the config? Just don't give me credit for the idea, I don't want to have anything to do with it :-) Kent > -Original Message- > From: Kent Johnson [mailto:[EMAIL PROTECTED] > Sent: Thursday, April 21, 2005 13:20 > Cc: tutor@python.org > Subject: Re: [Tutor] trouble setting the environment > > Ertl, John wrote: > >>All, >> >>I have program and init I want to "source" a .ksh file to set some >>environment variables and then use those variables in my program. >> >>Is this possible? I vaguely remember something about the system env and > > the > >>interpreters env being separate after the interpreter starts up. > > > What about making a shell file that sources your ksh file, then starts > python? > > Kent > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] trouble setting the environment
Ertl, John wrote: Kent, Good idea except that the environment that needs to be set depends on the answers to some of the input that I get in the Python program. Nothing is ever easy here. Maybe you could write a Python program that asks the questions, then spawns a shell task which sets the correct environment and runs another Python program that does the rest of the work? Or, a ksh wrapper that sources the right program then outputs its environment to a .py file that you can import to get the config? Just don't give me credit for the idea, I don't want to have anything to do with it :-) Kent -Original Message- From: Kent Johnson [mailto:[EMAIL PROTECTED] Sent: Thursday, April 21, 2005 13:20 Cc: tutor@python.org Subject: Re: [Tutor] trouble setting the environment Ertl, John wrote: All, I have program and init I want to "source" a .ksh file to set some environment variables and then use those variables in my program. Is this possible? I vaguely remember something about the system env and the interpreters env being separate after the interpreter starts up. What about making a shell file that sources your ksh file, then starts python? Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
RE: [Tutor] trouble setting the environment
Kent, Good idea except that the environment that needs to be set depends on the answers to some of the input that I get in the Python program. Nothing is ever easy here. Thanks for the ideas. John Ertl -Original Message- From: Kent Johnson [mailto:[EMAIL PROTECTED] Sent: Thursday, April 21, 2005 13:20 Cc: tutor@python.org Subject: Re: [Tutor] trouble setting the environment Ertl, John wrote: > All, > > I have program and init I want to "source" a .ksh file to set some > environment variables and then use those variables in my program. > > Is this possible? I vaguely remember something about the system env and the > interpreters env being separate after the interpreter starts up. What about making a shell file that sources your ksh file, then starts python? Kent > > For instance if I have a .ksh file called envSet.ksh: > > #!/bin/ksh > > unset OPSBIN > > export OPSBIN=/u/ops/bin > > ---end -- > > Then > > >>>>os.system(". envSet.ksh") > > 0 > >>>>os.getenv("OPSBIN") >>>> > > > What is the 0. I know that I can set the env using Python but all of the > correct env are in the .ksh files maintained by others. I would hate to > have to take the .ksh and tread each line and if it is an export turn that > into a python os.environ statement. > > Any ideas. > > Thanks > > John > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] trouble setting the environment
Ertl, John wrote: All, I have program and init I want to "source" a .ksh file to set some environment variables and then use those variables in my program. Is this possible? I vaguely remember something about the system env and the interpreters env being separate after the interpreter starts up. What about making a shell file that sources your ksh file, then starts python? Kent For instance if I have a .ksh file called envSet.ksh: #!/bin/ksh unset OPSBIN export OPSBIN=/u/ops/bin ---end -- Then os.system(". envSet.ksh") 0 os.getenv("OPSBIN") What is the 0. I know that I can set the env using Python but all of the correct env are in the .ksh files maintained by others. I would hate to have to take the .ksh and tread each line and if it is an export turn that into a python os.environ statement. Any ideas. Thanks John ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor