How do I set environment variables in one script and after piping the output to another script, I need certain environment variable to be set in first script and used in second script.
I am using python scripts.
python script1.py | python script2.py
in script1.py
, I am doing
os.environ["some_key"] = some_value
and in script2.py
, I am trying to read it as
saved_value = os.environ["some_key"]
When I try to run the above scripts as mentioned above,
Traceback (most recent call last):
File "script2.py", line 11, in <module>
filename = os.environ["some_key"]
File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
Is there anyway this can be corrected ? I specifically need it to be read from os.environ["some_key"]
in script2.py
as that file is part of bigger framework and cant change it. I have flexibility with with script1.py