Windows PowerShell 5.1: non-ASCII text piped into a native command arrives as `?`

Aperta Adatta ai principianti
#64,139 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@akhil9tiet ci sta già lavorando.

Dal 26/11/2026.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
powershell, rust
Ambito
backend, cli

Direzione di ricerca

Inizia leggendo codex-rs/shell-command/src/powershell.rs e la configurazione del prefisso in core/src/tools/runtimes/unified_exec.rs, inclusa la gestione esistente per #12496. Riproduci il problema in Windows PowerShell 5.1 con i passaggi forniti per git commit -F - e ispeziona i byte del messaggio di commit salvato. Il lavoro è completato quando il testo non ASCII passato tramite pipe arriva intatto e senza BOM attraverso i percorsi del prefisso descritti nell’issue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug CLI tool-calls windows-os
What version of Codex CLI is running?

0.172.0. The code cited below reads the same on today's main.

What subscription do you have?

Free

Which model were you using?

The default model (gpt-6-luna in the 0.156.1 session logs; the problem does not depend on the model)

What platform is your computer?

Windows 11 Home 25H2 (build 26200), Windows PowerShell 5.1.26100, git 2.55.0.windows.3, no PowerShell 7

What terminal emulator and version are you using (if applicable)?

None, codex exec

What issue are you seeing?

When Codex runs a command under Windows PowerShell 5.1, any non-ASCII text that command pipes into a native program reaches the program as ?. The program gets valid ASCII and exits 0, so nothing flags it.

I hit this with agents committing through @'…'@ | git commit -F -. In three runs out of three, a Co-authored-by: Zoé Lefèvre trailer was committed as Zo? Lef?vre, and the agent didn't notice, even the run that read the commit back with git show.

In these sessions Codex ran each command as powershell.exe -Command <command> with nothing before it, so $OutputEncoding, the encoding PowerShell uses for text piped into a native program, kept 5.1's default of ASCII (about_Preference_Variables). The UTF-8 prefix in codex-rs/shell-command/src/powershell.rs:13 doesn't cover this case: it's only added on the unified exec path (core/src/tools/runtimes/unified_exec.rs:549), and it sets [Console]::OutputEncoding, which is about what Codex reads back. PowerShell 7 defaults $OutputEncoding to UTF-8, so this shows up only when Codex falls back to powershell.exe, which is every Windows install without PowerShell 7.

What steps can reproduce the bug?

On Windows without PowerShell 7, ask Codex to run these in an empty folder:

git init -q demo
cd demo
'Zoé Lefèvre' | git -c user.name=x -c [email protected] commit -q --allow-empty -F -
git log -1 --format=%B

It prints Zo? Lef?vre, and the commit holds 0x3F bytes where é and è were. In one run the message also started with a UTF-8 BOM (EF BB BF): when the console's input code page is 65001, 5.1 writes one before anything it pipes to a native program, whatever $OutputEncoding says.

What is the expected behavior?

Zoé Lefèvre, as under PowerShell 7.

Additional information

Setting both encodings before the command fixes both symptoms:

$OutputEncoding = [Console]::InputEncoding = [System.Text.UTF8Encoding]::new()

With that line under Codex on the same machine, piped text arrived byte-exact with no BOM, and setting [Console]::InputEncoding raised no error. Adding it to the prefix, inside its try { } so the constrained language case from #12496 stays quiet, would cover it wherever the prefix runs.

Lingua principale
Rust
Stelle
136k
Fork
21.6k
Merge medio
1m
PR unite (30g)
997

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openai/codex

Tutte le issue di openai/codex

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.