Please help to advise how to use bash to catch the sub-process's stdout and send character to sub-process's stdin.
For example, use bash to control 10 videos convert by ffmpeg process, bash code needs to watch each ffmpeg process's stdout then decides if send the stdin command [+]/[-]/[c]/[q] or others command to control ffmpeg
the covert job would be something like
ffmpeg -i INPUT_n -c copy -f flv out_n.flv 2>&1 | grep "[MY_PATTERN]"
only when [MY_PATTERN] occurs this job shows word on it's stdout. I would like to use bash code to catch the job's stdout, do some decision according to the line included MY_PATTERN then feed command into the job's stdin. I guess I need to active new shell by bash to execute the job and interact its stdin/stdout. But how to ?
If I inderstood the question correct, you need to use
grep -q "MY_PATTERN". This would send aSIGPIPEto theffmpegprocess as soon as the pattern is matched.The following should work for you:
some_commandwould be executed as soon as the pattern is matched.