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

wsl2でwhileループに.exeのコマンドを含めると表示が崩れる問題の解決策

Last updated at Posted at 2020-05-22

問題

wsl2のwhileループの中でWindowsのコマンド(.exe)を実行すると表示が崩れる。

$ seq 10 | while read i; do ipconfig.exe &>/dev/null; echo $i; done
1

期待した結果が得られない。
ipconfig.exe以外の.exeのコマンドでも同様。
wsl1ではこの問題は発生しない。

原因

(恐らく).exeが標準入力を拾っている。

解決策

.exe</dev/nullを付ける。

ipconfig.exe </dev/null
$ seq 10 | while read i; do ipconfig.exe </dev/null &>/dev/null; echo $i; done
1
2
3
4
5
6
7
8
9
10
2
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
2
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?