Skip to content

Commit 1a7c9d8

Browse files
committed
gh-76303: Improve -x option documentation
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. Closes #76303.
1 parent 645f5c4 commit 1a7c9d8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Doc/using/cmdline.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,21 @@ 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+
@py -x "%~f0" %* & exit /b
530+
531+
Or, to specify the path to the Python interpreter explicitly::
532+
533+
@"C:\Path\to\python.exe" -x "%~f0" %* & exit /b
534+
535+
Unlike a shebang line which is a Python comment, this line is not valid
536+
Python syntax, and the :option:`-x` option is needed to skip it.
523537

524538

525539
.. option:: -X
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Improved documentation for the :option:`-x` command-line option, explaining
2+
its use for turning Python scripts into Windows batch files.

0 commit comments

Comments
 (0)