I’m working with an application that requires the user to source environment variables from a file into Bash. However, I cannot see these new env variables in Qt.
In Bash, once the file has been sourced, I can access the new variables via os.getenv(). But if I try to do that within Qt, it says those new variables don’t exist, i.e. get a return value of “None”.
Elsewhere in the Qt code, I can run a subprocess to execute Bash, call the source command, and gain access to the special commands from the external application, such as the code below (“ocpidev” is a command from the external application):
out = subprocess.run(["bash", "-c", f"source {self.ocpi_path}/cdk/opencpi-setup.sh -r && "
f"cd {self.user_proj_path} && "
f"ocpidev create project {proj_name}"],
stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
If I try the same thing when trying to access the env vars:
out = subprocess.run(["bash", "-c", f"source {self.ocpi_path}/cdk/opencpi-setup.sh -r && "
f"{os.getenv('OCPI_ROOT_DIR')}"], stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
then Qt returns
bash: None: command not found
How can I access the sourced variables from Bash?