Skip to content

gh-76303: Improve -x option documentation - #144857

Closed
RoryGlenn wants to merge 6 commits into
python:mainfrom
RoryGlenn:gh-76303-improve-x-option-docs
Closed

gh-76303: Improve -x option documentation#144857
RoryGlenn wants to merge 6 commits into
python:mainfrom
RoryGlenn:gh-76303-improve-x-option-docs

Conversation

@RoryGlenn

@RoryGlenn RoryGlenn commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

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.

The current documentation is a single line:

Skip the first line of the source, allowing use of non-Unix forms of #!cmd. This is intended for a DOS specific hack only.

This gives virtually no information about why the option exists or how to use it. As noted by @serhiy-storchaka in the issue, the purpose of -x is to allow turning Python scripts into Windows batch files (similar to how shebang lines work on Unix).

The expanded documentation now includes:

  • A clear explanation of the use case (Windows batch files)
  • Two practical examples of batch file header lines
  • An explanation of why -x is needed (the header line is not valid Python syntax)

📚 Documentation preview 📚: https://cpython-previews--144857.org.readthedocs.build/

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 python#76303.
Comment thread Doc/using/cmdline.rst Outdated
Comment thread Doc/using/cmdline.rst Outdated
RoryGlenn and others added 2 commits February 16, 2026 15:24
Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
Comment thread Doc/using/cmdline.rst
RoryGlenn and others added 2 commits February 24, 2026 13:27

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but it needs a review from Windows experts. Right now it is difficult to me to test this on Windows.

@serhiy-storchaka

Copy link
Copy Markdown
Member

@zooba, could you please take a look?

Comment thread Doc/using/cmdline.rst

.. code-block:: batch

@py -x "%~f0" %* & exit /b

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I normally use %~dpf0 to ensure the full path is used, which handles launching the batch file from a different directory. Any particular reason not to do that here?

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Aug 9, 2026
@serhiy-storchaka

Copy link
Copy Markdown
Member

Superseded by #155559, which merges main and removes the NEWS entry. Thank you @RoryGlenn for the contribution, your commit is preserved there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting merge docs Documentation in the Doc dir skip news stale Stale PR or inactive for long period of time.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

4 participants