Skip to content

Commit 3dcd722

Browse files
miss-islingtonserhiy-storchakaRoryGlennbrianschubert
authored
[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 4b04d5a) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Rory Glenn <glennrory@gmail.com> Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
1 parent e987990 commit 3dcd722

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
@@ -498,7 +498,25 @@ Miscellaneous options
498498
.. option:: -x
499499

500500
Skip the first line of the source, allowing use of non-Unix forms of
501-
``#!cmd``. This is intended for a DOS specific hack only.
501+
``#!cmd``.
502+
503+
This can be used to turn a Python script into a Windows batch file.
504+
Similarly to adding a shebang line and setting the executable bit on Unix,
505+
the extension of the Python script can be changed to ``.bat`` and the
506+
following line can be added at the start of the script:
507+
508+
.. code-block:: batch
509+
510+
@py -x "%~f0" %* & exit /b
511+
512+
Or, to specify the path to the Python interpreter explicitly:
513+
514+
.. code-block:: batch
515+
516+
@"C:\Path\to\python.exe" -x "%~f0" %* & exit /b
517+
518+
Unlike a shebang line which is a Python comment, this line is not valid
519+
Python syntax, and the :option:`-x` option is needed to skip it.
502520

503521

504522
.. option:: -X

0 commit comments

Comments
 (0)