[Tutor] commands module

ds ds-python-tutor at sidorof.com
Fri Dec 7 07:24:10 CET 2007


Evert Rol wrote:
>> So, I tried setting COLUMNS equal to 500 (arbitrarily large) prior to
>> going into python.  It seems to change back to 158 automatically
>> however.
>> For example, when I go into python, import commands, and execute
>> commands.getoutput('set') I find that COLUMNS is back to 158.  So, I
>> think my problem is that I don't know how to alter the set variable so
>> that it will stick long enough for the "ps ax" command to execute
>> properly.
>
> I've had this problem before (setting/altering shell variables when
> executing a command from Python, albeit using os.system() instead).
> What I'd use is:
> commands.getoutput('COLUMNS=500 ps ax')
> or similar. In your case, you've been able to solve in another way
> (and better, since environment independent, though still
> shell/ps-variant dependent), but sometimes one may need to set/change
> shell variables, like paths to dynamic libraries. The above should
> work (for more variables, just specify them all before the actual
> command, whitespace separated).
>
>
Thank you for mentioning that.  I'm pretty weak on bash, and had
monkeyed around with such things as set COLUMNS=500 on the previous line
in the shell program version, but hadn't actually looked up that syntax
yet, when I stumbled across the ps parameter that eventually I selected.

Thanks again.

ds


More information about the Tutor mailing list