我正在尝试使用 zbarcam 来监控 USB 摄像头并返回它看到的 QR 码。
我是 Zbarcam 和 Nodejs 的新手,但是已经做了相当多的研究,看不出哪里出了问题。我在 Ubuntu 12.04 LTS 上运行它,它在命令行中运行良好,但是当在 Node 的子进程中运行时,它什么也不返回。
如果我在命令行上运行以下命令效果很好,会看到 QR 码并返回代码:
zbarcam /dev/video0 --prescale=1280x720 -q --raw --nodisplay
但是当我在一个小的 nodejs 脚本中运行它时它只是挂起,我可以看到 cam 启用,但响应不会返回。
var exec = require('child_process').exec,child; child = exec('zbarcam /dev/video0 --prescale=640x480 -q --raw --nodisplay', function (error, stdout, stderr) { 如果(错误){ console.log(error.stack); console.log('错误代码:'+error.code); console.log('收到的信号:'+error.signal); } console.log('子进程标准输出:'+stdout); console.log('子进程 STDERR: '+stderr); }); child.on('exit', function (code) { console.log('子进程退出,退出码'+code); });
我怀疑这是我在 Node 中启动它的方式以及节点如何跟踪标准输出。
提前感谢大家。