[Tutor] using the modules and command prompt

Alan Gauld alan.gauld at blueyonder.co.uk
Mon Sep 1 22:23:31 EDT 2003


> use the winsound module - but i dont know how. 

Neither do I sorry...

> I would also like to know/if how you can python to open 
> up cmd.exe or similar and run commands such as ping.

First, ping is not in cmd.exe it's a separate exe file.
(C:\WINDOWS\System32\ping.exe on my system)

You can execute ping from python using 

os.system('ping www.python.org')

or to capture the output for later processing use os.popen()
There is also a recent addition to Python that makes this 
easier but I've forgotten its name, maybe someone else can 
advise...

But CD,MD etc for example are builtin commands of cmd.exe and 
to execute those you may need to use the command flags of CMD.EXE
Try typing HELP CMD at the DOS prompt. Usually  /C suffices:

os.system(r"CMD.EXE /C CD C:\TEMP")

HTH,

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld





More information about the Tutor mailing list