I’ve a shell script and a python script organized as follows (CAN NOT change the directory structure):
<code> ~
├── a.py
├── b
└── c.sh
</code>
<code> ~
├── a.py
├── b
└── c.sh
</code>
~
├── a.py
├── b
└── c.sh
The MWEs are as follows:
c.sh
<code>#!/bin/sh
export TEST1='hello'
cat <<-EOF > ./rcfile
export TEST2='world'
EOF
${SHELL} --rcfile ./rcfile
</code>
<code>#!/bin/sh
export TEST1='hello'
cat <<-EOF > ./rcfile
export TEST2='world'
EOF
${SHELL} --rcfile ./rcfile
</code>
#!/bin/sh
export TEST1='hello'
cat <<-EOF > ./rcfile
export TEST2='world'
EOF
${SHELL} --rcfile ./rcfile
a.py
<code>from subprocess import Popen, PIPE
p = Popen('./c.sh', cwd='./b', stdin=PIPE)
p.communicate(b'echo $TEST1necho $TEST2nexit')
</code>
<code>from subprocess import Popen, PIPE
p = Popen('./c.sh', cwd='./b', stdin=PIPE)
p.communicate(b'echo $TEST1necho $TEST2nexit')
</code>
from subprocess import Popen, PIPE
p = Popen('./c.sh', cwd='./b', stdin=PIPE)
p.communicate(b'echo $TEST1necho $TEST2nexit')
When I execute the shell script c.sh
, it shows both the variables as expected.
However, when executed from the python script a.py
, the inner variable i.e. TEST2
is not set.
I CAN NOT modify the shell script.
Is there a way to access both the variables TEST1
and TEST2
from the python script?