shell 节点生成:如果linux管道中的第一个进程退出,则退出整个命令

46scxncf  于 2023-03-13  发布在  Shell
关注(0)|答案(1)|浏览(117)

我正在使用这个命令和spawn函数。它工作。但是问题是,如果第一个命令退出,prc.on('exit', () => {...})将不会运行。这是因为spawn运行的sh脚本继续运行,或者没有得到退出代码。我不确定。

const command = 'ffmpeg -i [INPUT] -f mpegts pipe: 1 | while :; do dd bs=65536 count=1 2> /dev/null | redis-cli -x PUBLISH myChannel ; done';

const prc = spawn(command, [], { shell: true, stdio: ['ignore', 'ignore', 'pipe'] });

prc.on('exit', () => {...});//not firing when ffmpeg exits
0aydgbwb

0aydgbwb1#

使用此选项可在正常退出时执行操作:

prc.on('close', (exitCode) => {...});

这是对错误采取的措施:

prc.on('error', (stdErr) => {...});

相关问题