Very elementary help in using Python on Windows 98

Fred Pacquier fredp at mygale.org.nospam
Fri Sep 7 12:20:35 EDT 2001


"Jeff Melvaine" <jeffm52 at rivernet.com.au> said :

> I have begun to experiment with Python on Win98 on my personal laptop. 
> When I set up a script xxx.py and double click the icon to run it, I
> get a window (presumably some kind of debugging console)which lasts for
> a few seconds, flashes a message and dies instantly so I can't read it.
>  There is evidently a problem in my script somewhere, but how can I get
> the window to hang around long enough to see what it is?

Hey, for once there is a question in this group I can answer instead of ask 
myself :-)

What you are seeing is called a "DOS box" (or window). It is the old MS-DOS 
command-line interpreter, encapsulated in a (text-mode, console) Windows 
window -- a brain-dead equivalent of a Unix shell, also acting as "stdout" 
and "stderr" for text-mode C programs.

What happens is this : in typical Windows fashion, files with the .py 
extension are associated with the python.exe executable. When you double-
click such a file, Windows launches python.exe and passes it the file name 
as a parameter (juste hope it's really a python script :-). As python.exe 
is a text-mode, console app, a DOS box (the black window) is created to run  
python, which then runs the script.

Now, running DOS (or DOS apps) in Windows is regulated by special, strange 
things called PIF files. These set the options for how the DOS box is 
displayed (window, full-screen, # of lines, font etc) and how it relates to 
the rest of the system (memory access, sort-of-multitasking etc.). To 
further confuse things, in Explorer these appear as normal shortcuts to an 
executable (but with an MS-DOS icon).

When DOS is launched by Windows to run python to run a .py file (whew), it 
uses a default COMMAND.PIF file located in the Windows directory (the old 
DOS interpreter is called COMMAND.COM). By default this is set to close the 
DOS window when the program has terminated - that's why you can't read the 
traceback :)

If you right-click COMMAND.PIF in Explorer and choose "Properties", you 
will see a "Program" tab with a checkbox that says something like "Close 
when finished" (sorry, I only have French versions here, can't recall 
exactly)... Uncheck that and afterwards the DOS window will stay open so 
you can read its contents, until you manually close it.

Unfortunately this will be true for _all_ DOS windows launched by file 
association to DOS apps, not only Python. If this is inconvenient (it is 
:), you can consider creating a PYTHON.PIF file (in the same directory as 
python.exe, or under the windows dir), and change only that one.

Another way is to open the DOS box yourself (the icon is in the start menu, 
programs), then cd to the directory where your script is, then type "python 
myscript.py". Use "exit" to close the DOS box.

Such are the joys of life under MSWIN. Really feels strange teaching a Unix 
adept about these things :-))

HTH,
fp

-- 
YAFAP : http://www.multimania.com/fredp/



More information about the Python-list mailing list