'source cshrc file in python
I have to source a cshrc file from python and store the environment variables set by the cshrc file only in a dictionary. I am using this:
output = subprocess.check_output(
f'''source {file}; python -c "import os, json;
print(json.dumps(dict(os.environ)))"''',
shell=True, executable='/bin/csh')
env = json.loads(output)
However, this also prints these variables:
{'VENDOR': 'unknown', 'SHLVL': '1', 'PWD': <>, 'HOSTTYPE': 'x86_64-linux', 'HOST': <>,
'LOGNAME': <>, 'USER': <>, 'OSTYPE': 'linux', 'GROUP': 'users', 'MACHTYPE': 'x86_64',
variables_from_file}
How do I ensure only those variables are returned that are there from the file? I cannot filter out the above variables cause what if they are actually there in the file. I tried cleaning up environment before calling the subprocess but that also didn't work.
Any help would be appreciated?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
