2014-06-20 69 views
0

我想基本上是管两个命令行命令组合在一起,但我清楚地失去了一些东西:不知道为什么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 into the writer'); 
}); 

image_bin.stdout.pipe(image_txt.stdout); 

任何想法?

+2

您将'stdout'重定向到'stdout'?它不会工作:) –

+0

谢谢@IvanGrynko,那是我尝试的最后一件事。 image_bin.stdout.pipe(image_txt.stdin);还挂着,是你在想什么会工作? – socketwiz

+0

你想只是base64编码图像? – dylants

回答

0

谢谢@IvanGrynko和@dylants。我明确需要将stdout更改为stdin。 @dylants我尝试了在stdin,stderr和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); 
相关问题