我是 node.js 的新手,尝试连续执行两个进程,第一个进程的标准输出通过管道传输到第二个进程的标准输入。然后第二个进程的标准输出应该作为对 URL 请求的响应通过管道传输到变量 res 中。代码在这里。部分是别人写的所以可能是我理解有误:
var sox = spawn("sox", soxArgs)
var rubberband = spawn("rubberband", rubberbandArgs)
sox.stdout.pipe(rubberband.stdin)
rubberband.stdout.pipe(res) #won't send to res anything, why?
#rubberband.stdin.pipe(res) won't send to res anything, either!
#sox.stdout.pipe(res) will work just fine
sox.stdin.write(data)
sox.stdin.end()
#the actual sox process will not execute until sox.stdin is filled with data..?
任何帮助将不胜感激!我花了几个小时研究这个!
最佳答案
我认为您正在寻找的解决方案是将标准输入从 https://nodejs.org/api/process.html#process_process_stdin 传输到标准输出:
process.stdin.on('readable', () => {
const chunk = process.stdin.read();
if (chunk !== null) {
process.stdout.write(`data: ${chunk}`);
}
});
process.stdin.on('end', () => {
process.stdout.write('end');
});
关于node.js - 将 stdout 管道传输到 node.js 中另一个进程的 stdin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17355815/