Javascript 不确定node.js管道为什么挂起

Javascript 不确定node.js管道为什么挂起,javascript,node.js,Javascript,Node.js,我试图通过管道将两个控制台命令连接在一起,但我显然遗漏了一些东西: var child = require('child_process'); var image_bin = child.spawn('cat', ['./t.jpg']); var image_txt = child.spawn('openssl', ['base64']); image_txt.on('pipe', function(src) { console.error('something is piping i

我试图通过管道将两个控制台命令连接在一起,但我显然遗漏了一些东西:

var child = require('child_process');

var image_bin = child.spawn('cat', ['./t.jpg']);
var image_txt = child.spawn('openssl', ['base64']);

image_txt.on('pipe', function(src) {
  console.error('something is piping into the writer');
});

image_bin.stdout.pipe(image_txt.stdout);

有什么想法吗?

谢谢@IvanGrynko和@dylants。我确实需要把stdout改成stdin@dylants我尝试了在stdin、stderr和stdout上查找错误的不同变体,但没有看到任何错误。然而,当我开始监控stdout上的数据时,一切都开始起作用了。当我想起来的时候,我想这是有道理的。我想如果你不真正对数据做点什么,它就会阻塞。以下是我的想法:

var child = require('child_process');

var image_bin = child.spawn('cat', ['./t.jpg']);
var image_txt = child.spawn('openssl', ['base64']);

image_txt.stdout.on('data', function (data) {
  process.stdout.write(data.toString());
});

image_bin.stdout.pipe(image_txt.stdin);

你要把stdout重定向到stdout?这行不通:谢谢@IvanGrynko,这是我最后一次尝试。image_bin.stdout.pipeimage_txt.stdin;还有挂起,这就是你所想的吗?你是在尝试对图像进行base64编码吗?@dylants我肯定你会建议一些npm来实现这一点,但我更感兴趣的是学习如何将命令通过管道传输到一起。不,实际上,我会建议使用节点缓冲区和流的不同编码方式,但我理解,我不会这么做:我不确定openssl命令是否会等待标准中的输入,但您应该更改该管道以将其发送到image_txt.stdin,然后将on更改为image_txt.stdin.on“pipe”。通过这些更改,您至少会看到console.error消息。