How to run Python in Windows w/o popping a DOS box?

Bengt Richter bokr at oz.net
Fri Apr 22 11:43:52 EDT 2005


On 21 Apr 2005 20:12:40 -0700, Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:

>bokr at oz.net (Bengt Richter) writes:
>
>> I would try right-clicking the shortcut icon and selecting
>> properties, then select the shortcut tab and edit the target string
>> with s/python/pythonw/ and then click ok.
>> 
>> Then try double clicking the shortcut icon again.  If that does it,
>> you're home ;-) If not, post more symptoms.
>
>Hmm, I clicked properties and the word python doesn't appear in the
>shortcut string.  The shortcut string simply points to the .py file.
Ok, in that caseput <proper path>\pythonw.exe in front of that.
If you need to have current working directory some place particular,
there is a "Start in" slot for that on the same property tab.

>I think Windows knows to run Python because of some registry entry
>that maps the .py extension to python.exe.  I don't know which entry
>and changing it sounds a little bit dangerous.
Right, but you don't have to.
>
>I did see that I could select a button launch the dos box minimized,
>so it doesn't clutter up the screen.  That mostly solves the immediate
>problem.  A more complete solution (eliminate dos box altogether)
>would be nice, but I can live with an auto-minimized box.
>
As someone else suggested, you could also change the extension on your script
from .py to .pyw (and make that change in your shortcut too (or delete it
and make a new shortcut to the renamed script), or it won't find the renamed script ;-).

If you type

    assoc .py

in a cmd console window, you should get what category of file the windows
registry thinks .py files are. (it uses an intermediate category classification
so that the category can be associated with a program -- e.g., many extensions
might be categorized as text files beside .txt and wind up starting notepad).
To find what's associated with the file category (sorry, type), type

    ftype categoryname

For .py and .pyw on my system, you get this:

[ 8:30] C:\pywk\clp>assoc .py
.py=Python.File

[ 8:30] C:\pywk\clp>assoc .pyw
.pyw=Python.NoConFile

[ 8:30] C:\pywk\clp>ftype python.File
python.File=d:\python23\python.exe "%1" %*

[ 8:30] C:\pywk\clp>ftype python.NoConFile
python.NoConFile=D:\Python23\pythonw.exe "%1" %*

To get the whole list of assocs, type it without arg
then pipe to more or window's grep aka findstr (qgrep might be avail too)

[ 8:30] C:\pywk\clp>assoc | findstr py
.py=Python.File
.pyc=Python.CompiledFile
.pyo=Python.CompiledFile

[ 8:30] C:\pywk\clp>ftype | findstr py
Python.CompiledFile=D:\Python23\python.exe "%1" %*
Python.File=d:\python23\python.exe "%1" %*
Python.NoConFile=D:\Python23\pythonw.exe "%1" %*

(I'm not running py24 via association, and in fact rarely let the system do it,
since I need to run python explictly to pipe script input or output due to broken
windows piping in file-associated script execution on my system).

NB: If you type assoc or ftype with the "=" assignment string in format that it shows you,
(e.g. assoc .py=Python.File ) you will non-gui-wise be setting the association in the registry,
assuming you have privilege, so BE CAREFUL with that ;-)

-->> Especially don't mess with .exe association! That was tricky to recover from. (I actually
did that accidentally via Netscape's gui file association thing long ago, not from the command window ;-)

(Start>run>browse can find you regedt32.exe and you can do anything you want
to the registry from there, if you have the information and privilege. The information
part is harder to get that privilege in most cases ;-)

BTW you can do a whole bunch of stuff in the target slot of a shortcut.
E.g., my main one to start a "DOS box" from the start menu[1] has

    %SystemRoot%\system32\cmd.exe /x /k prompt [$T$H$H$H$H$H$H] $P$G& d:\vc98\bin\vcvars32.bat & home.cmd & title C++

Which starts cmd.exe with /x options and /k to keep it displayed, changes the prompt, runs the .bat script to
set environment for MSVC++, runs a little command script I made called home.cmd, which enables me easily to
come back to various project "home" directories, and sets a title in the title bar, so my window is ready to go.

A different one can set me up to use Borland's Delphi command line object pascal compiler, etc., settting
appropriate path and other environment variables, so the right set of command utilities are accessible,
and others that might have the same name are not.

[1](which uses shortcuts you can get at via start>settings>taskbar>start-menu-programs> etc)

Hm, I need to set my computer clock ...

Regards,
Bengt Richter



More information about the Python-list mailing list