[英]bash script, control processes with stdin/stdout
Please help to advise how to use bash to catch the sub-process's stdout and send character to sub-process's stdin. 请帮助建议如何使用bash捕获子进程的stdout并将字符发送到子进程的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 例如,使用bash控制ffmpeg进程转换的10个视频,bash代码需要观看每个ffmpeg进程的stdout,然后确定是否发送stdin命令
[+]
/ [-]
/ [c]
/ [q]
或其他命令来控制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. 仅当[MY_PATTERN]发生时,此作业才会在其标准输出上显示单词。 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.
我想使用bash代码捕获作业的标准输出,根据包含MY_PATTERN的行做一些决定,然后将命令输入到作业的标准输入中。 I guess I need to active new shell by bash to execute the job and interact its stdin/stdout.
我想我需要通过bash激活新的shell来执行作业并交互其stdin / stdout。 But how to ?
但是如何?
If I inderstood the question correct, you need to use grep -q "MY_PATTERN"
. 如果我正确地理解了这个问题,则需要使用
grep -q "MY_PATTERN"
。 This would send a SIGPIPE
to the ffmpeg
process as soon as the pattern is matched. 模式匹配后,这会将
SIGPIPE
发送到ffmpeg
进程。
The following should work for you: 以下应该为您工作:
ffmpeg -i INPUT_n -c copy -f flv out_n.flv 2>&1 | grep -q "[MY_PATTERN]" && some_command
some_command
would be executed as soon as the pattern is matched. 一旦模式匹配,就会执行
some_command
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.