diff --git a/ganga/GangaCore/Lib/Localhost/LocalHostExec.py.template b/ganga/GangaCore/Lib/Localhost/LocalHostExec.py.template index 2ab0d73256..f89b21ca7c 100644 --- a/ganga/GangaCore/Lib/Localhost/LocalHostExec.py.template +++ b/ganga/GangaCore/Lib/Localhost/LocalHostExec.py.template @@ -69,9 +69,18 @@ gangadir = ###GANGADIR### sys.path.insert(0, gangadir) sys.path.insert(0,os.path.join(os.getcwd(),PYTHON_DIR)) -runenv = os.environ.copy() -for key,value in environment.items(): - runenv[key] = value +runenv = dict() +result = subprocess.run(["env -i HOME=\"$HOME\" bash -lc '(set -o posix; set)'"], + capture_output=True, encoding='utf-8', + shell=True) +for line in result.stdout.split('\\n'): + varval = line.strip().split('=') + if len(varval) < 2: + pass + else: + content = ''.join(varval[1:]) + if not str(content).startswith('() {'): + runenv[varval[0]] = content outfile=open('stdout','w') errorfile=open('stderr','w') diff --git a/ganga/GangaCore/test/GPI/TestLocalCleanenv.py b/ganga/GangaCore/test/GPI/TestLocalCleanenv.py new file mode 100644 index 0000000000..246cb0d5a2 --- /dev/null +++ b/ganga/GangaCore/test/GPI/TestLocalCleanenv.py @@ -0,0 +1,21 @@ +import os +from GangaCore.testlib.GangaUnitTest import GangaUnitTest + + +class TestLocalCleanenv(GangaUnitTest): + def testLocalCleanenv(self): + from GangaCore.GPI import Job + from GangaTest.Framework.utils import sleep_until_completed, file_contains + + envname = 'LocalCleanenv_sjt5p' + os.environ[envname] = 'Test' + os.environ['PATH'] = os.environ['PATH'] + ':' + envname + + j = Job() + + j.submit() + + self.assertTrue(sleep_until_completed(j, 60), 'Timeout on completing job') + + self.assertEqual(j.status, 'completed') + self.assertFalse(file_contains(j.outputdir + '/stdout', envname))