[Tutor] commands module (Forwarded back to list)

Evert Rol evert.rol at gmail.com
Fri Dec 7 04:09:44 CET 2007


> 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).




More information about the Tutor mailing list