Skip to content

Commit 4b04d5a

Browse files
serhiy-storchakaRoryGlennbrianschubert
authored
gh-76303: Improve documentation of the -x command line option (GH-155559)
Expand the documentation for the -x command-line option to explain its purpose and usage for turning Python scripts into Windows batch files, with examples of batch file header lines. Co-authored-by: Rory Glenn <glennrory@gmail.com> Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
1 parent 7c072c1 commit 4b04d5a

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

Doc/using/cmdline.rst

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)