2

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?

3 Answers 3

2

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.

1

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

1

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .