This question nicely covers getting python scripts running under CMD.EXE without having to type a bunch of extra stuff - that is "> script" rather than "> python script.py".

However, I can't seem to get the same behavior under PowerShell. Entering "PS > script.py" there just gets me the "is not recognized as a cmdlet, function, operable program, or script file" error.

How do I get PowerShell to recognize the same file associations that CMD does?

link|improve this question

71% accept rate
feedback

3 Answers

up vote 2 down vote accepted

Aha, I've found the answer myself.

In PowerShell, scripts to be executed need to be proceeded by ".\"

So, "PS > script.py" doesn't work, but "PS > .\script.py" does.

Also, using this syntax adding ".py" to PATHEXT works fine under PowerShell.

link|improve this answer
feedback

Completely different direction but you could use IronPython to make .net executables and call those.

link|improve this answer
feedback

The same solution should work under Powershell: did you try adding .py to the PATHEXT environment variable?

link|improve this answer
Yes. Clearly, PowerShell isn't looking at the environment variables for this kind of thing. – Electrons_Ahoy May 14 '09 at 4:50
Scratch that, yes it is; I was just running commands the wrong way. See my answer. – Electrons_Ahoy May 14 '09 at 6:56
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.