sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #41431
Re: [Question #449241]: os.getenv is not getting new variable settings each time it is called
Question #449241 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/449241
Status: Answered => Open
Justin Pinkham is still having a problem:
OK, so the goal here is to kick off a series of about 30 test from 1
command, walk away and check the logs when finished for any errors. I
typically do this with a master batch file however for tests where the
environment variables need to change between each run this does NOT work
because of child processes inheriting the parents environment variables.
here is all the code of my latest test (which is what I think you
recommended above)
[justin.bat]
::Setting variables
start /wait c:\temp\test1.bat
start /wait c:\SikuliX\runsikulix_exit.cmd -r c:\SikuliX\scripts\justinOtest.sikuli
start /wait c:\temp\test2.bat
start /wait c:\SikuliX\runsikulix_exit.cmd -r c:\SikuliX\scripts\justinOtest.sikuli
[test1.bat]
setx EnvironmentVar1 Test1a /M
setx EnvironmentVar2 Test1b /M
exit
[test2.bat]
setx EnvironmentVar1 Test2a /M
setx EnvironmentVar2 Test2b /M
exit
[justinOtest]
from sikuli import *
import os
import time
EnvironmentVar1 = os.getenv('EnvironmentVar1')
EnvironmentVar2 = os.getenv('EnvironmentVar2')
print (EnvironmentVar1)
print (EnvironmentVar2)
my_testLog = open('c:\\Temp\\justin.log','a')#append to SikuliAPI if fails
dts = time.strftime('%Y-%m-%d %H:%M:%S')
Product = "Justin's environment variable Test log"
el = "\n"
my_testLog.write(dts+el+Product+el+EnvironmentVar1+el+EnvironmentVar2+el)
my_testLog.close()
[justin.log]
2017-02-02 07:43:36
Justin's environment variable Test log
Test2a
Test2b
2017-02-02 07:43:44
Justin's environment variable Test log
Test2a
Test2b
The first time it ran the log produced nothing (because the environment
variables didn't exist) the justin.log file was created with 0 bytes.
What you see here is the info from the 2nd run after the original bat
finished (which would release the inherited environment which had
nothing in it.) When I manually executed again I get the new values set
by the test2.bat. You can clearly see that I never see the correct
values for test1.bat. My hopes were that os.getenv would pickup the
values from the registry NOT the values from the parent command window.
I appreciate your quick responses and any additional information or
guidance on the matter.
--
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.