Logo ProcessKit API Reference

ConsoleEncoding Module

The encoding a **legacy console program** actually writes its output in on this host — the one answer needed to read a pre-UTF-8 Windows tool without mojibake. ProcessKit decodes captured output as UTF-8 by default, and that default is deliberately not changed by anything here: it is right for every modern tool, on every platform, and guessing a code page for a child that emits UTF-8 would corrupt output that reads correctly today. But a Windows console program written before UTF-8 — `ping`, `netstat`, `chkdsk`, most of the built-in tooling, and any application still built against the ANSI/OEM CRT — writes its non-ASCII text in a code page instead, so a UTF-8 decode turns every accented or Cyrillic character into `U+FFFD`. This module resolves **which** code page that is, so the fix is one call rather than a research project (`GetOEMCP` vs `GetConsoleOutputCP`, `chcp`, `CodePagesEncodingProvider`). Use it through `Command.ConsoleEncoding()`, which applies the result to text stdin and both captured streams, or take the `Encoding` directly from `current ()` for a `Pipeline`/`CliClient`/single-stream case.

Functions and values

Function or value Description

ConsoleEncoding.current ()

Full Usage: ConsoleEncoding.current ()

Parameters:
    () : unit

Returns: Encoding

The encoding a legacy console child of this process most likely writes its output in. **Windows:** the output code page of this process's console (what `chcp` reports, and what a child inherits), or the system OEM code page when this process has no console at all — a GUI application, a service, a detached test host. Resolved live on every call, because `chcp` can change the console's code page while the process runs. **Everywhere else:** UTF-8, the same instance `Command` already decodes with. Unix has no second, legacy console encoding to discover, so this is a genuine no-op rather than a platform-specific guess — and no P/Invoke happens on that path. **Best effort, never a failure.** A console code page the runtime has no data for falls back to UTF-8 rather than throwing: this is a convenience over a decoding default, and a builder call that threw because of the host's console settings would be worse than the mojibake it exists to prevent. A console already switched to UTF-8 (`chcp 65001`) resolves to exactly the default.

() : unit
Returns: Encoding

Type something to start searching.