Read from file or stdin

前端 未结 6 1191
北恋
北恋 2020-11-30 01:08

I am writing a utility which accepts either a filename, or reads from stdin.

I would like to know the most robust / fastest way of checking to see if stdin exists (d

6条回答
  •  余生分开走
    2020-11-30 02:07

    You may want to look at how this is done in the cat utility, for example.

    See code here. If there is no filename as argument, or it is "-", then stdin is used for input. stdin will be there, even if no data is pushed to it (but then, your read call may wait forever).

提交回复
热议问题