Fix: add CMD /C flag in shims to run batch scripts#46
Merged
Conversation
There was a problem hiding this comment.
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
approved these changes
Apr 21, 2025
4 tasks
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #45