在node.js中将标准输出管道化到另一个进程的标准输入

在node.js中将标准输出管道化到另一个进程的标准输入,node.js,pipe,stdin,Node.js,Pipe,Stdin,我是node.js新手,尝试连续执行两个进程,第一个进程的stdout通过管道传输到第二个进程的stdin。然后,第二个进程的stdout应该通过管道传输到变量res中,作为对URL请求的响应。代码在这里。其中一部分是别人写的,所以我可能有误解: var sox = spawn("sox", soxArgs) var rubberband = spawn("rubberband", rubberbandArgs) sox.stdout.pipe(rubberband.stdin)

我是node.js新手,尝试连续执行两个进程,第一个进程的stdout通过管道传输到第二个进程的stdin。然后,第二个进程的stdout应该通过管道传输到变量res中,作为对URL请求的响应。代码在这里。其中一部分是别人写的,所以我可能有误解:

  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..?

任何帮助都将不胜感激!我花了好几个小时研究这个

我认为您正在寻找的解决方案是从以下位置将stdin管道连接到stdout:

process.stdin.on('readable',()=>{
const chunk=process.stdin.read();
if(块!==null){
process.stdout.write(`data:${chunk}`);
}
});
process.stdin.on('end',()=>{
process.stdout.write('end');

});你看过文档了吗?@Nirk我读了,但不确定这是否解决了我的问题。有什么想法吗?我也希望能有一些有用的方法来调试这个东西..阅读--它给出了一个完整的
ps ax | grep ssh
的例子,我有点搞不清楚哪一个先运行,哪一个需要输出作为响应。