我是node.js的新手并尝试连续执行两个进程,第一个进程'stdout通过管道进入第二个stdin。然后第二个进程'stdout应该作为对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..?
任何帮助将不胜感激!我花了好几个小时研究这个!
答案 0 :(得分:1)
我认为您正在寻找的解决方案是从https://nodejs.org/api/process.html#process_process_stdin将标准输出管道传输到stdout:
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');
});