launch a .py file from a batch file

Dave Angel davea at ieee.org
Mon Jun 22 20:04:39 EDT 2009


CM wrote:
> I'd like to launch a number of programs, one of which is a Python GUI
> app, from a batch file launcher.  I'd like to click the .bat file and
> have it open all the stuff and then not show the "DOS" console.
>
> I can launch an Excel and Word file fine using, e.g.:
> Start "" "path/mydocument.doc"
>
> But if I try that with a Python file, like:
> Start "" "path/myPythonApp.py"
>
> It does nothing.  The others open fine and no Python app.
>
> However, if I do this instead (where path = full pathname to Python
> file),
> cd path
> myPythonApp.py
>
> it will launch the Python app fine, but it will show the "DOS"
> console.
>
> How can I get it to launch a .py file and yet not show the console?
>
> Thanks,
> Che
>
>   
Assuming you're running on Windows XP, try the following line in your 
batch file:
@start path\MyPythonApp.pyw

That's of course after you rename your script to a pyw extension.  
That's associated with pythonw, which doesn't need a command window.

Your batch file itself will still display a cmd window while it's 
running, but it'll finish quickly.  This is the same as when using one 
to start a spreadsheet or whatever.

If you cannot change the extension to the correct pyw extension, then 
try specifying the interpreter explicitly in the start line:

@start  c:\python26\pythonw.exe   path\MyPythonApp.py

You may need quotes in either of these cases, if you managed to include 
spaces in your pathnames.






More information about the Python-list mailing list