Correct text is the result of an encoding agreement at every boundary.
Start with the bytes on the wire
A browser sends the authoring form as an HTTP request whose body is UTF-8. That body is a sequence of bytes. The CGI process receives those bytes on standard input; they are not yet a JavaScript string and they are not safely interpreted by assuming the Windows console code page. A CGI wrapper that needs to feed the body to WSH must decode the input explicitly.
The authoring wrapper saves the request to a temporary directory and runs the framework's <code>ReadUtf8AsUtf16.ps1</code>. That script reads standard input as bytes, decodes it with a strict UTF-8 decoder, writes a UTF-16LE file without a byte-order mark, and records the resulting .NET string length as ASCII. The wrapper passes the character count in <code>CONTENT_LENGTH</code> and redirects the UTF-16 file to <code>cscript.exe</code>.
The count is measured after decoding because WSH receives a UTF-16 text stream. It describes the characters WSH will consume, rather than the number of UTF-8 bytes that arrived on the HTTP connection. Keeping byte length and decoded character length distinct prevents multibyte text from truncating or over-reading the form body.
WSH uses Unicode streams, the CGI response uses UTF-8
The wrapper runs <code>cscript.exe //U //nologo</code>. The <code>//U</code> switch makes CScript write redirected standard output and standard error in Unicode. The WSH application writes ordinary response headers and text through its standard streams; it does not need to teach each component about a console code page or emit binary UTF-8 bytes itself.
The wrapper captures stdout and stderr into separate temporary files. It does not concatenate them: stdout is the CGI response, while stderr is diagnostic output. The framework's <code>ForwardUtf8.ps1</code> reads each Unicode file and writes UTF-8 without a byte-order mark. The wrapper then sends the converted response bytes to Lighttpd and appends any converted error text to its CGI log. A successful request keeps protocol output and diagnostics in their proper channels.
This design handles the full path for a character such as a ballot mark: UTF-8 bytes from the browser, decoded request text, UTF-16 text consumed and produced by WSH, then UTF-8 response bytes returned to the browser. Setting <code>chcp 65001</code> in an unrelated terminal would not repair any of these service boundaries because that terminal is not in the request's process tree.
A test runner must decode what it asked CScript to write
The same rule applies when the framework runs its striped-trouser tests. The runner starts test entries with <code>cscript //U</code>, so their captured stdout and stderr are UTF-16LE. The process API now receives that encoding explicitly and decodes the captured bytes before searching for <code>TEST SUMMARY</code>. Before this change, the report file visibly contained successful summaries, but a parent that read the stream using the system code page could not parse them; the complete runner incorrectly reported that every suite had omitted its summary.
The process test also checks non-ASCII WSH output and a longer output that crosses the usual console buffer size. The output is first redirected to a temporary file, then read through the framework's SafeArray conversion rather than a handwritten byte loop. This verifies the actual redirection boundary, including the Unicode ballot character, rather than testing only an in-memory string.
Error paths use the same encoding discipline. The authoring wrapper converts stderr to UTF-8 before logging, while the framework process API returns captured output alongside the exit code and command line. The caller can then create a namespaced error with the full compiler message, stdout, and stderr. An exit code alone cannot explain a Unicode-related failure, and replacing a complete exception with a number would discard the evidence needed to fix it.
Keep one encoding contract at each edge
The useful lesson is to write down the encoding where a producer meets a consumer. HTTP form bodies enter as UTF-8 bytes. PowerShell decodes them strictly before WSH reads the body as UTF-16. CScript writes Unicode to redirected files under <code>//U</code>. PowerShell converts those files to UTF-8 before Lighttpd serves the response. The test runner captures CScript's Unicode output as UTF-16LE and parses text only after conversion.
This keeps HTML components, CGI response rendering, and test assertions independent from Windows console settings. Each generic boundary has a small owner: the CGI wrapper handles transport conversion, <code>os.shell.Process</code> handles child output capture, and the application handles headers and response content. When a character is missing or a summary cannot be found, the trace tells me which decoder to inspect.
