[3.13] gh-76303: Improve documentation of the -x command line option (GH-155559) (GH-155567)

serhiy-storchaka <[email protected]> Tue, 11 Aug 2026 10:53:06 -0400 (EDT)
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/3dcd722017c50cef4b614d1493b3c084d0206c66
commit: 3dcd722017c50cef4b614d1493b3c084d0206c66
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-08-11T14:52:47Z
summary:

[3.13] gh-76303: Improve documentation of the -x command line option (GH-155559) (GH-155567)

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.
(cherry picked from commit 4b04d5abcd8476af4c4a67fcf2263c856fdabb47)

Co-authored-by: Serhiy Storchaka <[email protected]>
Co-authored-by: Rory Glenn <[email protected]>
Co-authored-by: Brian Schubert <[email protected]>

files:
M Doc/using/cmdline.rst

diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst
index 28a6d0bbbc8cdb1..738ffac5c6e8b56 100644
--- a/Doc/using/cmdline.rst
+++ b/Doc/using/cmdline.rst
@@ -498,7 +498,25 @@ Miscellaneous options
 .. option:: -x
 
    Skip the first line of the source, allowing use of non-Unix forms of
-   ``#!cmd``.  This is intended for a DOS specific hack only.
+   ``#!cmd``.
+
+   This can be used to turn a Python script into a Windows batch file.
+   Similarly to adding a shebang line and setting the executable bit on Unix,
+   the extension of the Python script can be changed to ``.bat`` and the
+   following line can be added at the start of the script:
+
+   .. code-block:: batch
+
+      @py -x "%~f0" %* & exit /b
+
+   Or, to specify the path to the Python interpreter explicitly:
+
+   .. code-block:: batch
+
+      @"C:\Path\to\python.exe" -x "%~f0" %* & exit /b
+
+   Unlike a shebang line which is a Python comment, this line is not valid
+   Python syntax, and the :option:`-x` option is needed to skip it.
 
 
 .. option:: -X

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]