Skip to content

shift renumbers %1 and leaves %* alone, so a batch wrapper cannot drop its own first argument and forward the rest

args quoting · case

bothsilentagentciscriptthird-partyrepro: verifiedpercent-star-unshifted
Affectscmd, windows
Fails assilent
Mechanismpercent star unshifted
Safe fixconsume arg downstream

Nothing, for a long time. A .cmd shim that takes a name and forwards everything after it works for months. Then a caller passes nine arguments and the ninth is missing from the child. No error, no truncation notice, no clue in the log — the argument is simply not there.

Terminal window
@echo off
echo BEFORE_STAR=[%*]
shift
echo AFTER_STAR=[%*]
echo AFTER_1=[%1]
> wrapper.cmd one two three
BEFORE_STAR=[one two three]
AFTER_STAR=[one two three]
AFTER_1=[two]

shift did its job: %1 moved from one to two. %* did not move at all.

%* is not built from the numbered parameters. It is the command tail exactly as it arrived, and shift only renumbers %1 through %9. The two are different views of the same invocation, and only one of them is shiftable.

So a wrapper that must consume its first argument and forward the rest has no correct expansion available. What it reaches for instead is

Terminal window
child.exe %2 %3 %4 %5 %6 %7 %8 %9

and that is where the famous eight-argument ceiling comes from. Be precise about this, because it is usually reported backwards: cmd.exe does not limit you to eight arguments. The ceiling belongs to the workaround, and it appears only because %* was unavailable.

Do not consume the argument in batch at all. Forward %* untouched and let the program you dispatch read its own leading token:

Terminal window
REM the hook name stays in the line; run.mjs reads argv[2] itself
"%WH_NODE%" "%~dp0run.mjs" %*

Nothing shifts, so %* is still correct, and the ceiling never exists. This is the shape win-hooks settled on after the positional version capped its hooks at eight arguments.

If you must keep the positional form, quote every one of them:

Terminal window
child.exe "%~2" "%~3" "%~4" "%~5" "%~6" "%~7" "%~8" "%~9"

%~n strips surrounding quotes, and re-quoting puts exactly one layer back, so an argument containing a space survives instead of splitting into two. Unquoted %2 %3 loses that argument boundary silently, which is the same failure mode as the missing ninth argument and just as hard to see.

Both halves of this fail quietly. A dropped ninth argument and a split third argument produce a child that runs successfully with the wrong input, so the exit code is 0 and the log looks normal. Nothing in the batch language will tell you; the only way to see it is to have the child print its own argv, which is also the repro above.