Skip to content

Fix: add CMD /C flag in shims to run batch scripts#46

Merged
zkochan merged 1 commit into
pnpm:mainfrom
kcastellino:main
Apr 21, 2025
Merged

Fix: add CMD /C flag in shims to run batch scripts#46
zkochan merged 1 commit into
pnpm:mainfrom
kcastellino:main

Conversation

@kcastellino

Copy link
Copy Markdown

Closes #45

@zkochan zkochan requested a review from Copilot April 21, 2025 23:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the batch script execution by adding the CMD /C flag when generating shims, ensuring that batch files run correctly. The changes include:

  • Updating the CLI runtime detection logic to append "/C" when the target program is CMD.
  • Adding new tests for batch scripts in test/test.js.
  • Inserting a new batch fixture file in test/setup.js.

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

File Description
test/test.js Added tests for batch script shim generation.
test/setup.js Added a new fixture "src.bat" to support batch shim testing.
src/index.ts Modified searchScriptRuntime to set additionalArgs to "/C" for CMD.
Files not reviewed (1)
  • test/snapshots/test.js.snap: Language not supported
Comments suppressed due to low confidence (1)

src/index.ts:280

  • Consider verifying that the comparison for 'cmd' is robust against casing variations, ensuring that the '/C' flag is consistently applied for all CMD invocations.
const additionalArgs = program === 'cmd' ? '/C' : ''

@zkochan zkochan merged commit 30cd364 into pnpm:main Apr 21, 2025
zkochan added a commit that referenced this pull request May 11, 2026
* fix(sh): escape `/C` so MSYS doesn't drop the cmd switch

The sh shim generated for a `.cmd` / `.bat` target runs the script via
`exec cmd /C "<path>" "$@"`. Under Git Bash (MSYS), the path-conversion
layer that runs when bash launches a native Win32 process rewrites
arguments matching POSIX-path heuristics — a bare `/C` is treated as a
path and rewritten to `C:\`. cmd.exe then never sees the `/C` flag,
starts interactively, and reads the rest of the calling script as input
until it hits EOF.

Prefixing with `//` is the MSYS escape: `//C` survives the translation
and reaches cmd.exe as `/C`. The cmd shim is unaffected (`%*` argument
passing in cmd.exe doesn't get this treatment), so the change is scoped
to `generateShShim`.

Bug introduced in #46; manifests as cmd.exe banner output when invoking
any cmd-shim-wrapped `.cmd` from Git Bash.

---
Written by an agent (Claude Code, claude-opus-4-7).

* test(e2e): regression test for MSYS /C escape

Generates an sh shim wrapping a `.cmd` target and invokes it via Git
Bash. Asserts the script's output appears (proving the `/C` switch
reached cmd.exe) and that cmd.exe's interactive banner did not (proving
the bug — where MSYS rewrote `/C` to `C:\` — is not present).

Windows-only; the suite is skipped elsewhere.

---
Written by an agent (Claude Code, claude-opus-4-7).

* fix(sh): scope MSYS escape to the cmd runtime

Apply the /C → //C rewrite only when opts.prog is 'cmd' (the runtime
inferred for .cmd/.bat targets). Avoids mangling legitimate /C-like args
from shebang-derived configurations on non-MSYS systems, where the
program would see //C verbatim.

Addresses review feedback on #55.
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.

Shims created for batch scripts on Windows don't run the batch script

3 participants