Python scripts from DOS

M

Mark Carter

On my machine, I can go to a DOS shell, and type
myscript.py
This will cause the script to be run as a python script. So that bit
works.

On another machine, on which python was set up without admin
privileges, if I type
myscript.py
it will open the "Open With" dialog box. It wont let me execute it
with python.exe. It asks me the same question every time, too. If I
type
python myscript.py
then everything works fine.

Is there a way of setting up the "other" machine so that it replicates
the behaviour of my machine?
 
T

Thomas Jollans

On my machine, I can go to a DOS shell, and type
myscript.py
This will cause the script to be run as a python script. So that bit
works.

On another machine, on which python was set up without admin
privileges, if I type

Which operating systems are we talking about?
myscript.py
it will open the "Open With" dialog box. It wont let me execute it
with python.exe.

What does that mean, exactly? What happens when you try to select python?
It asks me the same question every time, too. If I
type
python myscript.py
then everything works fine.

Is there a way of setting up the "other" machine so that it replicates
the behaviour of my machine?

Depends on which OS we're talking about. I'm guessing you're using
Windows, but I don't know which version, and I don't possess the
Registry-fu you'll probably need.
 
R

Rebelo

On my machine, I can go to a DOS shell, and type
   myscript.py
This will cause the script to be run as a python script. So that bit
works.

On another machine, on which python was set up without admin
privileges, if I type
   myscript.py
it will open the "Open With" dialog box. It wont let me execute it
with python.exe. It asks me the same question every time, too. If I
type
   python myscript.py
then everything works fine.

Is there a way of setting up the "other" machine so that it replicates
the behaviour of my machine?

http://docs.python.org/release/2.6.5/using/windows.html for python
2.6.5 on windows
especially chapter 3.3.4. Executing scripts

for python 2.7 :
http://docs.python.org/using/windows.html
same chapter

for python 3.0 :
http://docs.python.org/py3k/using/windows.html#executing-scripts
 
D

Dave Angel

Mark said:
On my machine, I can go to a DOS shell, and type
myscript.py
This will cause the script to be run as a python script. So that bit
works.

On another machine, on which python was set up without admin
privileges, if I type
myscript.py
it will open the "Open With" dialog box. It wont let me execute it
with python.exe. It asks me the same question every time, too. If I
type
python myscript.py
then everything works fine.

Is there a way of setting up the "other" machine so that it replicates
the behaviour of my machine?
Assuming you're talking Windows XP, Vista or Win7 you can do the following:

There are registry settings in two places, hklm and hkcu. If you only
have one user on the machine, it probably doesn't matter. in that case,
there's a nice commandline way to make these associations.

assoc creates associations beteween a file extension and a string
ftype creates an association between that string and an executable
program.

On my machine, assoc .py shows

..py=Python.File

and ftype Python.File shows

python.file="C:\PrgFiles\APYTHO~1\python.exe" "%1" %*



Or you can read the following link:

http://msdn.microsoft.com/en-us/library/ms724475(VS.85).aspx


DaveA
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top