/**
 * 指纹监听函数
 */
const dpath=require('path');
const log = require("."+dpath.sep+"set_log").clog;
const spawn = require('child_process').spawn
const process=require('process')
let finger_monitor={
    //需要启动服务名称
    cmdStr:'CrtechFingerprintWeb.exe',
    cmdPath:'',
    workerProcess:null,
    runFingerMonitor:function (path){
      this.cmdPath = path + dpath.sep+"static"+dpath.sep+"software";
      log.info("指纹程序存放目录为：【"+this.cmdPath+"】");
      // 执行命令行，如果命令不需要路径，或就是项目根目录，则不需要cwd参数：
      this.workerProcess = spawn(this.cmdStr, { cwd: this.cmdPath, maxBuffer: 10240 * 1024 });

     /* this.exit();
      this.originPrintOut();
      this.errorPrintOut();
      this.beforeCloseOut();*/
    },
    //退出指纹程序监听
    exit:function(){
      process.on('exit',function(){
        this.workerProcess.kill();
      });
    },
    //正常输出监听
    originPrintOut:function(){
      this.workerProcess.stdout.on('data', function (data) {});
    },
    //错误输出监听
    errorPrintOut:function(){
      this.workerProcess.stderr.on('data', function (data) {});
    },
    //关闭之前输出监听
    beforeCloseOut:function (){
      this.workerProcess.on('close', function (code) {});
    }
}

module.exports=finger_monitor