我正在尝试使用zbarcam来监控USB凸轮并拍摄它看到的QR码 .
我是Zbarcam和Nodejs的新手,但做了大量研究,看不出有什么问题 . 我在Ubuntu 12.04 LTS上运行它,它在命令行中工作正常,但是当在Node中的子进程中运行时,它什么都不返回 .
如果我在命令行上运行以下命令它工作得很好,看到QR码并回拍代码:
zbarcam /dev/video0 --prescale=1280x720 -q --raw --nodisplay
但是当我在一个小的nodejs脚本中运行它时,它只是挂起,我可以看到凸轮启用,但响应不会返回 .
var exec = require('child_process').exec,child;
child = exec('zbarcam /dev/video0 --prescale=640x480 -q --raw --nodisplay', function (error, stdout, stderr) {
if (error) {
console.log(error.stack);
console.log('Error code: '+error.code);
console.log('Signal received: '+error.signal);
}
console.log('Child Process STDOUT: '+stdout);
console.log('Child Process STDERR: '+stderr);
});
child.on('exit', function (code) {
console.log('Child process exited with exit code '+code);
});
我怀疑这是我在Node中启动它的方式以及节点如何跟踪stdout .
感谢所有提前 .
1 回答
你可以使用zbar npm,这是我的github https://github.com/flatr0ze/node-zbar上的fork,带有更新的自述文件
运行npm install zbar并按照自述文件运行,它应该可以正常工作
这是一个不含Npm的例子:https://github.com/cloudpower/qr2wifi/blob/f28f3bf7062b58c8adca2751faaf4e070fa124b4/index.js
祝好运!