Skip to content

Commit f3648f4

Browse files
miss-islingtonserhiy-storchakaRoryGlennbrianschubert
authored
[3.14] gh-76303: Improve documentation of the -x command line option (GH-155559) (GH-155566)
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 3efd623 commit f3648f4

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
@@ -501,7 +501,25 @@ Miscellaneous options
501501
.. option:: -x
502502

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

506524

507525
.. option:: -X

0 commit comments

Comments
 (0)