Skip to content

Add -OutputEncoding for decoding program output - #12

Merged
HalRiveria merged 3 commits into
mainfrom
feat/output-encoding
Oct 28, 2026
Merged

HalRiveria merged 3 commits into
mainfrom
feat/output-encoding

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

What was wrong. Program output was always decoded in the console's code page. On a default Windows console (code page 437), a program that writes UTF-8 came back garbled. A test program printing café 日本語 came back as caf├⌐ .... Many cross-platform command-line tools write UTF-8, so non-ASCII file names in their output were mangled.

What changed.

  • -OutputEncoding on Start-PkProcess, Invoke-PkProcessWithTimeout and Invoke-PkProcessBatch sets how stdout/stderr are decoded.
  • It takes a name ('utf-8', 'utf8'), a code page number, or a [System.Text.Encoding].
  • Batch commands and dispatcher jobs can carry their own OutputEncoding key, which overrides the batch-wide value.
  • An unknown name fails the call with a clear message.
  • Default unchanged: left unset, output is decoded in the console's code page as before, which is what Windows' own tools write.

The README covers it next to the timeout option.

Testing.

  • The harness compiles a small program that writes UTF-8 bytes to stdout and stderr, and checks:
    • 'utf-8' decodes both intact;
    • code page 437 garbles them, so the option really takes effect;
    • a batch-wide value applies to every command, and a per-command key overrides it;
    • an unknown name is refused.
  • 206 assertions pass on Windows PowerShell 5.1 and PowerShell 7.6. The branch merged with Return objects instead of hashtables from results #11 passes 213 on 5.1.
  • The new assertions fail against main (no such parameter).

🤖 Generated with Claude Code

HalRiveria and others added 2 commits October 28, 2026 04:05
Output was always decoded in the console's code page, so a program
that writes UTF-8 came back garbled on a default console (code page
437): "café" read as box-drawing characters. -OutputEncoding takes a
name ('utf-8', 'utf8'), a code page number or an Encoding, on
Start-PkProcess, Invoke-PkProcessWithTimeout and Invoke-PkProcessBatch,
plus an OutputEncoding key on batch commands and dispatcher jobs.
Unset, behaviour is unchanged, since Windows' own tools write in the
console code page. An unknown name fails with a clear message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ding in callbacks

The parameter shares its name with PowerShell's preference variable, and
the batch's closures captured it, so an -OnComplete scriptblock saw the
kit's value (empty, or a string) instead of PowerShell's Encoding. The
value now moves to a kit-private name before the closures are built.
Also asserts that a code page given as text ('437') works.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HalRiveria
HalRiveria merged commit ebb435f into main Oct 28, 2026
2 checks passed
@HalRiveria
HalRiveria deleted the feat/output-encoding branch October 28, 2026 09:11
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.

2 participants