nushell / nushell

A new type of shell
https://www.nushell.sh/
MIT License
32.82k stars 1.7k forks source link

`kill` command fails in a non-English Windows environment #13476

Open stknohg opened 4 months ago

stknohg commented 4 months ago

Describe the bug

I tested on Nushell 0.96.0 in Japanese Windows 11.

kill command fails with the following message in a non-English Windows environment.

invalid utf-8 sequence of 1 bytes from index 0

The steps to reproduce are as follows,

# Current codepage is 932 (= Default codepage in Japanese Windows environment)
~> chcp
現在のコード ページ: 932

~> ps | where name == pwsh.exe | select pid name
╭───┬───────┬──────────╮
│ # │  pid  │   name   │
├───┼───────┼──────────┤
│ 0 │ 19368 │ pwsh.exe │
╰───┴───────┴──────────╯

# Failed to kill the pwsh.exe process.
~> kill 19368
Error:   × failed to convert output to string
   ╭─[entry #21:1:1]
 1 │ kill 19368
   · ──┬─
   ·   ╰── invalid utf-8 sequence of 1 bytes from index 0
   ╰────

There are two workarounds.

Workaround 1 : Use taskkill command directly

~> chcp
現在のコード ページ: 932

~> ps | where name == pwsh.exe | select pid name
╭───┬───────┬──────────╮
│ # │  pid  │   name   │
├───┼───────┼──────────┤
│ 0 │ 19368 │ pwsh.exe │
╰───┴───────┴──────────╯

# taskkill command succeeds.
~> taskkill /pid 19368
成功: PID 19368 のプロセスに強制終了のシグナルを送信しました。

Workaround 2 : Change codepage temporary

# Change codepage 932 to 65001 temporary
~> chcp 65001
Active code page: 65001

~> ps | where name == pwsh.exe | select pid name
╭───┬───────┬──────────╮
│ # │  pid  │   name   │
├───┼───────┼──────────┤
│ 0 │ 19368 │ pwsh.exe │
╰───┴───────┴──────────╯

# kill command succeeds.
~> kill 19368
SUCCESS: Sent termination signal to the process with PID 19368.

How to reproduce

  1. Start Nushell in non-English Windows environment
  2. Invoke kill command.

Expected behavior

The process is killed without errors.

Screenshots

No response

Configuration

key value
version 0.96.0
major 0
minor 96
patch 0
branch main
commit_hash a88c3f48e281ce50dd2a0518ff8e899314e427b5
build_os windows-x86_64
build_target x86_64-pc-windows-msvc
rust_version rustc 1.77.2 (25ef9e3d8 2024-04-09)
rust_channel 1.77.2-x86_64-pc-windows-msvc
cargo_version cargo 1.77.2 (e52e36006 2024-03-26)
build_time 2024-07-24 08:42:22 -05:00
build_rust_channel release
allocator mimalloc
features default, sqlite, system-clipboard, trash
installed_plugins

Additional context

No response

Embers-of-the-Fire commented 3 months ago

If we don't use encoding sniffers such as chardetng, we seem to need to map all possible Windows internal encoding type representations one by one. Looks like a very troublesome repetitive task :(.