launch a .py file from a batch file

C

CM

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
 
D

Dave Angel

CM said:
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.
 
P

Paul Moore

2009/6/23 C M said:
Well, I renamed my script to have a .pyw extension, and then ran the line
above.  Without quotes, it doesn't find it (because I have spaces in the
path).
With quotes it just opens a console and does nothing (does not launch the
app).

Any ideas?

Use

@start "" "path\MyPythonApp.pyw"

The first item in quotes is the window title. If you only include the
path (in quotes) it's taken as a title, which is why you need the
second set of quotes.

Paul.
 
D

Dave Angel

Paul said:
Use

@start "" "path\MyPythonApp.pyw"

The first item in quotes is the window title. If you only include the
path (in quotes) it's taken as a title, which is why you need the
second set of quotes.

Paul.
CM - Paul is right. If you have to use quotes, then you also need the
extra argument to hold the "title" for the command window that won't be
created. Stupid syntax on "Start.exe". I seldom hit that because I try
not to put anything in a directory with spaces in it, like "Program
Files" or "Documents and Settings"

I have uncovered dozens of bugs in other people's programs over the
years that were triggered by spaces in the pathname. It's not so bad
now, but still can bite you.
 
C

Che M

Use

@start "" "path\MyPythonApp.pyw"

The first item in quotes is the window title. If you only include the
path (in quotes) it's taken as a title, which is why you need the
second set of quotes.

Paul.

Unfortunately, when I try that it says "Windows cannot find [that
file]", etc.
And yet I am copying the filename right from the file manager and it
IS
there.

What's also odd is that if I open the file using cd and then just
putting
the filename on the next line, that file (which I gave a .pyw
extension)
doesn't open, but a file that has a .py extension does.

Any ideas?
Thanks.
Che
 
D

Dave Angel

Che said:
Use

@start "" "path\MyPythonApp.pyw"

The first item in quotes is the window title. If you only include the
path (in quotes) it's taken as a title, which is why you need the
second set of quotes.

Paul.

Unfortunately, when I try that it says "Windows cannot find [that
file]", etc.
And yet I am copying the filename right from the file manager and it
IS
there.

What's also odd is that if I open the file using cd and then just
putting
the filename on the next line, that file (which I gave a .pyw
extension)
doesn't open, but a file that has a .py extension does.

Any ideas?
Thanks.
Che
If you run the xx.pyw file interactively, does it work? If not, perhaps
the pyw file association is broken. It, along with the py association,
should have been set up by the Python install.

You can check it (and fix it) with
assoc and ftype. Here's what mine look like:

M:\>assoc .pyw
..pyw=Python.NoConFile

M:\>ftype Python.NoConFile
Python.NoConFile="C:\ProgFiles\Python26\pythonw.exe" "%1" %*


Or, as I said in an earlier message, you could explicitly specify the
interpreter to be run on the start line.

Something like:
@start "notitle" "c:\ProgFiles\Python26\pythonw.exe" "path\script.pyw"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top