File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -519,7 +519,25 @@ Miscellaneous options
519519.. option :: -x
520520
521521 Skip the first line of the source, allowing use of non-Unix forms of
522- ``#!cmd ``. This is intended for a DOS specific hack only.
522+ ``#!cmd ``.
523+
524+ This can be used to turn a Python script into a Windows batch file.
525+ Similarly to adding a shebang line and setting the executable bit on Unix,
526+ the extension of the Python script can be changed to ``.bat `` and the
527+ following line can be added at the start of the script:
528+
529+ .. code-block :: batch
530+
531+ @ py -x " %~f0 " %* & exit /b
532+
533+ Or, to specify the path to the Python interpreter explicitly:
534+
535+ .. code-block :: batch
536+
537+ @ " C:\Path\to\python.exe" -x " %~f0 " %* & exit /b
538+
539+ Unlike a shebang line which is a Python comment, this line is not valid
540+ Python syntax, and the :option: `-x ` option is needed to skip it.
523541
524542
525543.. option :: -X
You can’t perform that action at this time.
0 commit comments