Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

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.

share|improve this answer

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

share|improve this answer

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

share|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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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