使用管道字符 | child_process 产卵
Using a pipe character | with child_process spawn
我在 raspberry pi 上 运行ning nodejs,我想 运行 一个子进程来生成网络摄像头流。
节点外我的命令是:
raspivid -n -mm matrix -w 320 -h 240 -fps 18 -g 100 -t 0 -b 5000000 -o - | ffmpeg -y -f h264 -i - -c:v copy -map 0:0 -f flv -rtmp_buffer 100 -rtmp_live live "rtmp://example.com/big/test"
对于 child_process
我必须分解每个参数
var args = ["-n", "-mm", "matrix", "-w", "320", "-h", "240", "-fps", "18", "-g", "100", "-t", "0", "-b", "5000000", "-o", "-", "|", "ffmpeg", "-y", "-f", "h264", "-i", "-", "-c:v", "copy", "-map", "0:0", "-f", "flv", "-rtmp_buffer", "100", "-rtmp_live", "live", "rtmp://example.com/big/test"];
camera.proc = child.spawn('raspivid', args);
然而它在 |
字符上窒息:
error, exit code 64
Invalid command line option (|)
如何使用这个管道字符作为参数?
这已在另一个问题中得到回答:Using two commands (using pipe |) with spawn
总而言之,对于 child.spawn
,args
中的所有内容都应该是您的 'raspivid' 命令的参数。在您的情况下,管道及其后的所有内容实际上是 sh
.
的参数
解决方法是调用 child.spawn('sh', args)
,其中 args 是:
var args = ['-c', <the entire command you want to run as a string>];
我在 raspberry pi 上 运行ning nodejs,我想 运行 一个子进程来生成网络摄像头流。
节点外我的命令是:
raspivid -n -mm matrix -w 320 -h 240 -fps 18 -g 100 -t 0 -b 5000000 -o - | ffmpeg -y -f h264 -i - -c:v copy -map 0:0 -f flv -rtmp_buffer 100 -rtmp_live live "rtmp://example.com/big/test"
对于 child_process
我必须分解每个参数
var args = ["-n", "-mm", "matrix", "-w", "320", "-h", "240", "-fps", "18", "-g", "100", "-t", "0", "-b", "5000000", "-o", "-", "|", "ffmpeg", "-y", "-f", "h264", "-i", "-", "-c:v", "copy", "-map", "0:0", "-f", "flv", "-rtmp_buffer", "100", "-rtmp_live", "live", "rtmp://example.com/big/test"];
camera.proc = child.spawn('raspivid', args);
然而它在 |
字符上窒息:
error, exit code 64
Invalid command line option (|)
如何使用这个管道字符作为参数?
这已在另一个问题中得到回答:Using two commands (using pipe |) with spawn
总而言之,对于 child.spawn
,args
中的所有内容都应该是您的 'raspivid' 命令的参数。在您的情况下,管道及其后的所有内容实际上是 sh
.
解决方法是调用 child.spawn('sh', args)
,其中 args 是:
var args = ['-c', <the entire command you want to run as a string>];