strange subprocess behavior when calling ps

Roger Davis rbd at hawaii.edu
Wed Nov 17 07:47:09 CET 2010


Thanks, Ned! That really helps to explain what is going on. Now, just
a couple more questions and I think I will know all I need to know.

First, I *still* don't quite understand why this happens with my 2.6.6
interpreter but not my 2.6.1, and why another of the respondents to
this thread (Chris) could not duplicate this problem with his own
2.6.6 environment. Is there something defective with my Python
environment having to do with the 2.6.6 upgrade I installed directly
from python.org? (Chris used Fink, apparently.) If so, how can I clean
it up? I do have an easier time believing that this is a mangled
installation issue now that the problem has essentially been reduced
to the handling of an environment variable which I can well imagine
could be easily garbled somewhere in a version mismatch scenario.

Second, I do need to make this work on multiple platforms, primarily
Linux in addition to the Mac but also with a potential variety of
Python releases on both MacOS and Linux. I'm not sure if Linux will
object to this COMMAND_MODE business, I guess I'll just have to try
and see what happens. Any thoughts on that?

Finally, to split hairs a bit concerning your suggested solution, I
have a question about the additional env={'COMMAND_MODE': 'unix2003'}
argument. This works for me, but my reading of the subprocess
documentation leads me to believe that this will actually wipe out the
entire environment that would otherwise be inherited from the parent
and replace it with that single setting. I don't think this has any
ill effects here with regard to ps, at least none I can detect at the
moment, but wouldn't a perhaps safer solution be to do

os.environ['COMMAND_MODE']= 'unix2003'

prior to the Popen() to instead augment/correct the existing
environment which will then later be inherited by the child, assuming
no explicit env= optional argument is used? This also works for me,
and I think I'm more inclined to go this route unless you can think of
a good reason not to do so.

Thanks very much for your help!



More information about the Python-list mailing list