From 040166bbb7d28051be2b529efed190299131d5c3 Mon Sep 17 00:00:00 2001 From: ojkoenig Date: Sun, 14 Aug 2022 15:40:08 +0200 Subject: [PATCH] Pass env correctly --- examples/exec_scripts/exec_mapdl.py | 7 ++++++- examples/exec_scripts/exec_python.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/exec_scripts/exec_mapdl.py b/examples/exec_scripts/exec_mapdl.py index 1ccf9a62d..c19f49b6c 100644 --- a/examples/exec_scripts/exec_mapdl.py +++ b/examples/exec_scripts/exec_mapdl.py @@ -6,6 +6,7 @@ """ import json +import os import subprocess from ansys.rep.common.logging import log @@ -39,9 +40,13 @@ def execute(self): # Use properties from resource requirements num_cores = self.context.resource_requirements["num_cores"] + # Pass env vars correctly + env = dict(os.environ) + env.update(self.context.environment) + # Form command cmd = f"{exe} -b -i {inp_file['path']} -o {out_file['path']} -np {num_cores}" # Execute command log.info(f"Executing: {cmd}") - subprocess.run(cmd, shell=True, check=True) + subprocess.run(cmd, shell=True, check=True, env=env) diff --git a/examples/exec_scripts/exec_python.py b/examples/exec_scripts/exec_python.py index 8a67495d7..99125660f 100644 --- a/examples/exec_scripts/exec_python.py +++ b/examples/exec_scripts/exec_python.py @@ -5,6 +5,7 @@ """ import json +import os import subprocess from ansys.rep.common.logging import log @@ -38,9 +39,13 @@ def execute(self): # Use properties from resource requirements # None currently + # Pass env vars correctly + env = dict(os.environ) + env.update(self.context.environment) + # Form command cmd = f"{exe} {script_file['path']} {inp_file['path']}" # Execute log.info(f"Executing: {cmd}") - subprocess.run(cmd, shell=True, check=True) + subprocess.run(cmd, shell=True, check=True, env=env)