How to capture environment state after running a shell script.

Gerard Flanagan grflanagan at yahoo.co.uk
Wed Mar 14 04:52:40 EDT 2007


On Mar 13, 7:54 pm, attn.steven.... at gmail.com wrote:
> On Mar 13, 5:57 am, "Gerard Flanagan" <grflana... at yahoo.co.uk> wrote:
>
> > Hello,
>
> > I have a third party shell script which updates multiple environment
> > values, and I want to investigate (and ultimately capture to python)
> > the environment state after the script has run.
>
> First close the input so that the (sub) process
> knows to terminate and flush the output.  Then,
> you can read from the output:
>
> import subprocess
> import popen2
>
> p = subprocess.Popen(["/bin/sh"], stdin=subprocess.PIPE,
>         stdout=subprocess.PIPE)
>
> p.stdin.write("env -i FOO=BAR\n")
> p.stdin.close()
> status = p.wait()
> ret = p.stdout.readlines()
> p.stdout.close()
>
>
> print ret
>

Perfect! Works a charm. Thanks for helping me out.

Gerard





More information about the Python-list mailing list