LoginSignup
1
0

More than 5 years have passed since last update.

Git > raw_input() > sys.stdinをopen("/dev/tty")する理由

Last updated at Posted at 2018-04-16

とある人の疑問

gitのフックって sys.stdin をopen("/dev/tty") にしないとraw_input 出来ないのね…
この仕様なんなんだろ

ロシア語?のサイト
http://qaru.site/questions/433523/how-is-it-possible-to-use-rawinput-in-a-python-git-hook

2 ответов

において、gitコマンドのプロセス(21801)とpythonのプロセス(21802)がある。

21802に対してfd3が/dev/ttyに紐付いている。

あと、ロシア語は分からない。

When you call open you get a NEW file descriptor. 0, 1, 2 are already open when the process starts. So 3 is a newly created file descriptor. Use .fileno() on an existing file object to see the file descriptor number. – jim mcnamara Jun 6 '13 at 11:26

fdの0, 1, 2はすでに開いていて、3が新たに作られるfile descriptor。

21802に対してfd3が/dev/ttyに紐付いている。

ということで、sys.stdin=open('/dev/tty')をしないとダメな気がする。

link

ロシア人が参考にした英語サイト(Stackoverflow)もあった。上記ロシア語サイトからリンクされている。

実はgoogle検索するとこちらのサイトが上位に出てきていた。最初からこちらを読めばよかったのか。

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