Skip to content

fix: normalize forward slashes in paths for cmd.exe on Windows (fixes #818)#876

Open
leno23 wants to merge 6 commits into
sharkdp:masterfrom
leno23:fix/windows-forward-slash-paths-818
Open

fix: normalize forward slashes in paths for cmd.exe on Windows (fixes #818)#876
leno23 wants to merge 6 commits into
sharkdp:masterfrom
leno23:fix/windows-forward-slash-paths-818

Conversation

@leno23
Copy link
Copy Markdown

@leno23 leno23 commented May 16, 2026

Summary

  • On Windows, the default cmd.exe shell treats / as a switch prefix, so commands like ./target/debug/foo.exe failed while --shell=none worked.
  • Normalize path-like tokens (./…, ../…, C:/…, *.exe, etc.) to use \ before passing the command line to cmd /C.
  • Leave URLs (://) and non-path tokens (e.g. echo hello/world) unchanged.

Test plan

  • Unit tests in util::windows_cmd (all platforms)
  • cargo clippy -- -D warnings
  • Windows integration test windows_forward_slashes_in_executable_path (CI)

Closes #818

Made with Cursor

leno23 and others added 4 commits May 17, 2026 03:49
cmd.exe treats '/' as a switch prefix, so benchmark commands like
./target/debug/foo.exe failed under the default shell while --shell=none
worked. Normalize path-like tokens to backslashes before passing the
command line to cmd /C.

Fixes sharkdp#818

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
…p#818 branch

Co-authored-by: Cursor <cursoragent@cursor.com>
shell_words::split treats backslashes as escapes and broke Windows paths
in commands like `echo x >> C:\Users\...\file.log`, causing
execution_order_tests to fail on Windows CI.

Co-authored-by: Cursor <cursoragent@cursor.com>
@leno23
Copy link
Copy Markdown
Author

leno23 commented May 16, 2026

Pushed a fix for Windows CI: shell_words::split was mangling C:\\Users\\... paths in echo >> file redirect commands. Replaced with quote-aware splitting that does not treat \\ as escapes.

Co-authored-by: Cursor <cursoragent@cursor.com>
@leno23
Copy link
Copy Markdown
Author

leno23 commented May 16, 2026

CI is green on all targets (including Windows after the shell_words / integration-test fixes). Ready for review when you have time — thanks!

@leno23
Copy link
Copy Markdown
Author

leno23 commented May 16, 2026

Friendly ping — Windows forward-slash fix is CI-green on all targets. Thanks!

@AngelicosPhosphoros
Copy link
Copy Markdown

AngelicosPhosphoros commented May 16, 2026

Have you tested the form without MAX_PATH limit?
From https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#win32-file-namespaces :

For file I/O, the \\?\ prefix to a path string tells the Windows APIs to disable all string parsing and to send the string that follows it straight to the file system. For example, if the file system supports large paths and file names, you can exceed the MAX_PATH limits that are otherwise enforced by the Windows APIs.

@leno23
Copy link
Copy Markdown
Author

leno23 commented May 17, 2026

Good point — this PR only rewrites /\ in path-like tokens so cmd.exe does not treat / as a switch; it does not create extended paths or change how hyperfine opens files.

For user-supplied \\?\ paths that still use forward slashes, the normalizer now treats the \\?\ prefix explicitly (same /\ pass as other paths). Added unit tests for:

  • \\?\C:/Users/foo/very/long/path/to/tool.exe → backslashes in the path segment
  • \\?\C:\Users\foo\tool.exe left unchanged when already backslash-only

I have not added a Windows CI job that constructs a real >260-character path on disk (would be environment-dependent); happy to add an integration test if you want that coverage in CI.

Explicitly treat Win32 `\\?\` prefixes when normalizing `/` for cmd.exe,
and add unit tests for forward- and backslash forms.

Co-authored-by: Cursor <cursoragent@cursor.com>
@AngelicosPhosphoros
Copy link
Copy Markdown

Thanks.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default execution on Windows fails when using forward slashes as directory separator

2 participants