【问题标题】:Have 2 blocking scripts interact with each other in linux有 2 个阻塞脚本在 linux 中相互交互
【发布时间】:2023-03-04 12:45:01
【问题描述】:

我有 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)。

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

【问题讨论】:

标签: linux node.js bash shell ffmpeg


【解决方案1】:

我想你想要这样的东西:

# 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

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

【讨论】:

    猜你喜欢
    • 2011-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多