0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PowerShell で sbt を実行したときに日本語を文字化けさせない方法

Posted at

PowerShell で sbt を起動した際、出力(ファイルパス等)の日本語部分が文字化けしてしまうことがあります。
これは、PowerShell のシステムコンソールの出力エンコーディング設定が Shift JIS (CP932) であるのに対し、sbt の出力エンコーディングが UTF-8 であるためです。

有名な解決法として、chcp コマンドを前もって実行しておき、コンソールのコードページを 932 から 65001 (=UTF-8) に変更する方法が挙げられます。

chcp 65001
sbt

さて、この方法でも問題はないのですが、chcp でコードページを変更するとコンソールの表示がクリアされてしまいます。

chcp-clear-console.gif

これが気になる場合は、PowerShell ネイティブな方法でコンソールの出力エンコーディング設定を変更することで回避できます:

[Console]::OutputEncoding = [Text.Encoding]::GetEncoding('utf-8')
sbt

この設定は現在の PowerShell セッションの間だけ持続します。同セッション内で Shift JIS に戻したい場合は、以下のコマンドを実行します:

[Console]::OutputEncoding = [Text.Encoding]::GetEncoding('shift_jis')

pwsh-notclear-console.gif

参考リンク

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?