Skip to content

Enable batchfiles to run via CreateProcessW - #30490

Open
ahewitson-ops wants to merge 4 commits into
bazelbuild:masterfrom
ahewitson-ops:batchfile_longpaths
Open

Enable batchfiles to run via CreateProcessW#30490
ahewitson-ops wants to merge 4 commits into
bazelbuild:masterfrom
ahewitson-ops:batchfile_longpaths

Conversation

@ahewitson-ops

Copy link
Copy Markdown

Description

Enables Batchfiles to be ran via CreateProcessW even when their paths exceed MAX_PATH.
Adds a Manifest for long path awareness to tw.exe and xml.exe.

Looks to fix #30431

Motivation

#29921 helped us Windows users by enabling long paths for all .exe files, but specifically left out Batch/cmd files. Specifically because .bat and .cmd files must be run through an interpreter like cmd.exe, as stated in the CreateProcessW documentation.

However, testing shows that CreateProcessW can in fact handle being given a .bat or .cmd file above long paths, and silently rewrites the call to shunt it over to cmd.exe without the user having to do anything. The only caveat is that cmd.exe does not understand the \\?\ prefix for long paths and so a .bat/.cmd path must be passed without it.

I want to also note the manifest changes came from @nwatkiss in another PR for handling long paths HERE.

Build API Changes

No

Checklist

  • I have added tests for the new use cases (if any).
  • I have updated the documentation (if applicable).

Release Notes

RELNOTES: Enable Batchfiles to also be ran when their paths exceed MAX_PATH.

@ahewitson-ops
ahewitson-ops marked this pull request as ready for review July 28, 2026 14:29
@github-actions github-actions Bot added area-Windows Windows-specific issues and feature requests awaiting-review PR is awaiting review from an assigned reviewer labels Jul 28, 2026
@ahewitson-ops

Copy link
Copy Markdown
Author

As Marc pointed out in the Windows channel, in theory this could be working but slow because windows first tries to run it as a PE binary and then silently rewrites to cmd.exe when that fails.

@iancha1992 iancha1992 added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Windows Windows-specific issues and feature requests awaiting-review PR is awaiting review from an assigned reviewer team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: Batch files cannot be path shortened enough

2 participants