Running python programs without opening a separate shell

In powershell, when I run a python program with:

> python hello.py 

The program launches and prints any output directly in the powershell window in which I work. But when I try to do this without calling python explicitly:

 > hello.py 

a separate window opens. How can I fix this, so it behaves the same as with an explicit python call?

+4
source share
1 answer

If you add .PY to the .PY environment PATHEXT , you should be able to run .\hello.py or just .\hello in the current console. Otherwise, it will be a ShellExecute related Python.File command (check ftype Python.File ), which launches a new console. I checked this by temporarily changing the environment variable:

 $env:pathext = $env:pathext + ";.PY" 
+9
source

Source: https://habr.com/ru/post/1443556/


All Articles