Displaying os commands

Peter Hansen peter at engcorp.com
Tue May 25 13:12:42 EDT 2004


Perochon Sebastien wrote:
> Thanks for all your answers.
> I just wanted to know if python got a variable to enable/disable the output.
> It seems not.

Unlike in the DOS batch file language, with Python the commands are
not just automatically "echoed" to the console.  Any output
that you want you have to generate.

It's trivial to do, however, as shown by the examples you've been
given.  The best option if you really want this is just to define
your own "system" command:

def system(cmd):
     print cmd   # include the "prompt" if you wish...
     os.system(cmd)

Then just use system('dir') instead of os.system('dir').

-Peter



More information about the Python-list mailing list