Read fails after tcpreplay with error: 0: Resource temporarily unavailabl

前端 未结 3 1377
刺人心
刺人心 2021-01-13 18:47

I have a very simple script to run. It calls tcpreplay and then ask the user to type in something. Then the read will fail with read: read error: 0: Resource temporarily una

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-13 19:23

    While the C solution works, you can turn off nonblocking input in one line from the command-line using Python. Personally, I alias it to "setblocking" since it is fairly handy.

    $ python3 -c $'import os\nos.set_blocking(0, True)'
    

    You can also have Python print the previous state so that it may be changed only temporarily:

    $ o=$(python3 -c $'import os\nprint(os.get_blocking(0))\nos.set_blocking(0, True)')
    $ somecommandthatreadsstdin
    $ python3 -c $'import os\nos.set_blocking(0, '$o')'
    

提交回复
热议问题