使用pipe道字符| 与child_process产卵

我在树莓派上运行nodejs,我想运行一个subprocess来产生一个摄像头stream。

在节点之外,我的命令是:

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 (|)

我如何使用这个pipe道字符作为参数?

这已经在另一个问题中得到了回答: 使用两个命令(使用pipe道|)与产卵

总之,在child.spawn中, args所有内容应该是你的“raspivid”命令的一个参数。 在你的情况下,pipe道及其后的所有内容实际上是sh参数。

解决方法是调用child.spawn('sh', args) ,其中args是:

  var args = ['-c', <the entire command you want to run as a string>];