当前位置: 动力学知识库 > 问答 > 编程问答 >

powershell - What is windows doing when a command like python is run in a terminal?

问题描述:

This is more of a question about the general processes that windows performs when a command is run in powershell

My understanding is that when the command

C:\>python

is run in powershell, it references a python executable stored somewhere else. This path was added for me when I installed python so I didn't have to bother with knowing where python.exe (or whatever it is called) is located. However the python command also works with scripts so you can run

C:\>python script.py

to execute a python script without opening up a shell. So then is it referencing a different executable when the script.py is included, or is the python.exe command that it is referencing able to do multiple things depending how it is executed?

网友答案:

The shell (not only powershell, but cmd.exe, bash etc) parses the command line, takes the first token, tryes to find an internal command or an executable that matches the token, and in case of success executes what was found passing to it the command line as an argument.

In your case the shell splits python script.py to ['python', 'script.py'], finds c:\python27\python.exe using PATH and PATHEXT environment variables, and creates proccess python.exe with python script.py as an argument.

网友答案:

If you open up python.exe in IDA Pro or another disassembler or debugger, you can trace the execution and see that it has multiple paths depending on how it is run.

It is not referencing a different executable, it is looking at how it was executed (does it have arguments passed or not? what are those arguments?) and those various factors control how python.exe is executed.

分享给朋友:
您可能感兴趣的文章:
随机阅读: