Embedding UNIX Commands

D-Man dsh8290 at rit.edu
Mon Feb 12 21:07:49 CET 2001


You can use the system function :

import os
os.system( "whoami" )

I don't think you can use setenv -- that is a csh thing, and system()
won't even start up a shell (AFAIK).  Even if it did, it wouldn't do
you any good since that shell would terminate and its environment
would be meaningless.  (Also, on Linux systems bash is the default
shell)

It would probably be better if you described what you want to
accomplish with these commands and then people can come up with a
different way that wouldn't rely on the underlying system (and PATH).

If you simply want to change the environment of your python process
you can :

import sys
sys.env[ "VAR" ] = "value"


(also possibly the sys.setenv() function, try  dir( sys ) , and  print
sys.setenv.__doc__ )

HTH,
-D

On Mon, Feb 12, 2001 at 07:11:31PM +0000, O'Rourke Clodagh-corour01 wrote:
| Hi All,
| I'm wondering could anyone advise me on what is the best way to embed unix commands such as setenv and whoami in a Python/Tkinter application.  Would it be to put them into a C module or can it be done directly in python?
| 
| Thanks,
| Clodagh O' Rourke.
| 




More information about the Python-list mailing list