0
1

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 5 years have passed since last update.

Windows CMD.EXE コンソールで UTF-8 の入出力

Last updated at Posted at 2016-05-31

scala (java も同じだけど) で UTF-8 のコンソール入出力をしたい場合は、起動時に -Dfile.encoding=UTF-8 をオプションとして付けるとよいみたい。
> scala -Dfile.encoding=UTF-8 ...

CMD.EXE で UTF-8 の表示をするには chcp 65001 すればよいのだが、素の CMD.EXE では、自分の環境だけかもしれないが monospace 有効(?)になっているらしく、表示が崩れてしまう。

こんな感じ。(本当は「实施例」と入力している)
image

仕方がないので、生の CMD.EXE はあきらめて ConEmu というのを使うことにした。
(公式ページ ⇒ http://conemu.github.io/)

実行するとこんな感じ。
image

でも、コンソールから入力した「实施例」がちゃんと表示できたのはいいけど、何も処理せずにプログラムが終了してしまった。
これは断じて自分のプログラムの問題ではなくて、 Windows の CMD.EXE の CON デバイスの問題(仕様?)らしい。つまり、CON デバイスから UTF-8 文字列を読み込もうとすると、そこで EOF になってしまっているようなのだ。(chcp 65001 の後 > type con とやって何か漢字を入力してみると分かる)

でもなぜか Cygwin の cat.exe は EOF にならずにエコーを返してくれる。
image

ということで、最終的には、次のようなコマンドラインとなった。
image

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?