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?


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.


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


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

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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