Bash reading STDOUT stream in real-time

后端 未结 2 825
没有蜡笔的小新
没有蜡笔的小新 2021-01-14 05:43

I have searched for this and expected to find hundreds of solutions yet found none !

I would like to read the STDOUT stream and wait for a specific string to appear,

2条回答
  •  鱼传尺愫
    2021-01-14 06:05

    From this unix.stackexchange answer I got following solution:

    cmd_which_streams_new_lines \
    | while read -r line; do
      # process your line here
      echo "${line}"
    
      # when you're done, break the loop (be prepared for messy stderr)
    done
    

提交回复
热议问题