Python script plays arguments when running from PATH on Windows

I know that my title is not descriptive, so let me try to explain it here.

I usually execute my python script as follows:

D:\github\Miscellaneous-Programs\Python>python check.py -h
hello
['check.py', '-h']

Now, what I have done is adding a folder D:\github\Miscellaneous-Programs\Pythonto my windows variable path. Than I tried to execute my script as follows:

C:\Users\noob>check -h
hello
['D:\\github\\Miscellaneous-Programs\\Python\\check.py']

As you can see, he did not show the argument -hthat I gave him.

My check.py

import sys
print "hello"
print sys.argv

If I remove the print sys.argvscript from the above python, it works fine in both cases that I mentioned above, then it prints "hello" perfectly.

So my question is how to execute a python script that takes some command line arguments after adding the script to the environment variable.

- python script Windows, chmod +x check.py.

chmod cygwin, .

Cygwin output

noob@noob-PC ~
$ chmod +x check.py

noob@noob-PC ~
$ ./check.py h
['./check.py', 'h']
+6
2

Windows script , #!, , , . , Windows, - WinAPI ShellExecute, :

, . , .txt Microsoft WordPad. , TXT :

"C:\Program Files\Windows NT\Accessories\Wordpad.exe" "%1"

. MSDN

, . - :

"C:\Program Files\Python\Python.exe" "D:\github\Miscellaneous-Programs\Python\check.py"

, , .bat check.bat:

python check.py %*

(. SO . check.py python, )

+5

PATH script script.py -h . , , , , . , reg query HKCR\.py /ve, ( Python.File) reg query HKCR\Python.File\shell\open\command /ve. "C:\Program Files\Python Launcher (64-bit)\py.exe" "%1" %*. , , script.py -h, py.exe , script ( "%1"), , script ( %*). , %* .

+4

All Articles