有2个阻塞脚本在linux中相互交互

时间:2014-11-18 20:22:33

标签: linux node.js bash shell ffmpeg

我有2个阻止shell脚本,我希望彼此进行交互。有问题的脚本是peerflix(nodejs脚本)和ffmpeg(一个简单的bash脚本)。

会发生什么:Peerflix启动,将数据提供给ffmpeg bash脚本,在完成时终止peerflix。

因此,一旦peerflix启动,它会立即输出2行并阻塞:

[08:15 PM]-[vagrant@packer-virtualbox-iso]-[/var/www/test]-[git master] 
$ node /var/www/test/node/node_modules/peerflix/app.js /var/www/test/flexget/torrents/test.torrent -r -q
listening: http://10.0.2.15:38339/
process: 9601

我必须将侦听地址提供给ffmpeg bash脚本:

#!/bin/sh
ffmpeg -ss 00:05:00 -i {THE_LISTENING_PORT} -frames:v 1 out1.jpg
ffmpeg -ss 00:10:00 -i {THE_LISTENING_PORT} -frames:v 1 out2.jpg

bash脚本完成后,我必须终止peerflix脚本(因此我输出了PID)。

我的问题是如何实现这一目标?

1 个答案:

答案 0 :(得分:0)

我想你想要这样的东西:

# Start the node process in the background
node /var/www/test/node/node_modules/peerflix/app.js /var/www/test/flexget/torrents/test.torrent -r -q &
# Get the PID of the node process
PID=$!

# Run your stuff    
ffmpeg -ss 00:05:00 -i {THE_LISTENING_PORT} -frames:v 1 out1.jpg
ffmpeg -ss 00:10:00 -i {THE_LISTENING_PORT} -frames:v 1 out2.jpg

# Stop the node process
kill $PID

您可以将其放在一个脚本中,或者让一个节点脚本启动/杀死节点进程作为包装器并在中间运行另一个脚本。希望这会有所帮助。

相关问题