【问题标题】:Error spawn /usr/bin/clamscan in NodeJS ClamScan在 NodeJS ClamScan 中产生错误 /usr/bin/clamscan
【发布时间】:2021-02-24 04:45:28
【问题描述】:

我正在运行一个简单的 clamscan 示例。

const NodeClam = require('clamscan');

let options = {
    debug_mode: true,
    // clamdscan: {
    //     socket: '/var/run/clamav/clamd.ctl', // This is pretty typical
    //     host: '127.0.0.1', // If you want to connect locally but not through socket
    //     port: 3310, // Because, why not
    //     timeout: 300000, // 5 minutes
    //     local_fallback: true, // Use local preferred binary to scan if socket/tcp fails
    //     path: '/usr/bin/clamdscan', // Special path to the clamdscan binary on your server
    //     config_file: '/etc/clamav/clamd.conf', // A fairly typical config location
    //     multiscan: false, // You hate speed and multi-threaded awesome-sauce
    //     reload_db: true, // You want your scans to run slow like with clamscan
    //     active: false, // you don't want to use this at all because it's evil
    //     bypass_test: true, // Don't check to see if socket is available. You should probably never set this to true.
    // },
    preference: 'clamscan' 
};


async function some_function() {
    try {
        // Get instance by resolving ClamScan promise object
        console.log("-------------------hello world------------------------------");
        const clamscan = await new NodeClam().init(options);
        //console.log(clamscan);
        console.log("--------------------------------------------------------hello world------------------------------------------------");
        const {good_files, bad_files} = await clamscan.scan_dir('/home/abhishek/Desktop/JSINFO', );
        console.log("----------------------------------------------------------hello world--------------------------------------------------------------------");
        console.log(good_files);
    } catch (err) {
       console.log(err);
    }
};
 
some_function();

但是,我收到这样的错误:

节点蛤:标准输出: node-clam:已感染! (node:109042) UnhandledPromiseRejectionWarning: E​​rror: Error: spawn /usr/bin/clamscan --no-summary --stdout.

在位置 /usr/bin/clamscan 中有一个 clamscan 文件。但这还是要来了

【问题讨论】:

    标签: node.js clamav


    【解决方案1】:

    我通过使用 Promise 函数而不是 async 函数成功让 scan_dir 工作......我猜这是库中的一个问题,但如果你使用它,它应该可以工作:)

    const NodeClam = require('clamscan');
    const ClamScan = new NodeClam().init();
    
    
    function main() {
      // Get instance by resolving ClamScan promise object
      ClamScan.then(async clamscan => {
          try {
              // You can re-use the `clamscan` object as many times as you want
              const path = '/path/to/your/folder';
              const version = await clamscan.get_version();
              console.log(`ClamAV Version: ${version}`);
      
              clamscan.scan_dir(path, (err, good_files, bad_files, viruses) => {
                if (err) return console.error(err);
    
                console.log(good_files);
            
                if (bad_files.length > 0) {
                    console.log(`${path} was infected. The offending files (${bad_files.join (', ')}) have been quarantined.`);
                    console.log(`Viruses Found: ${viruses.join(', ')}`);
                } else {
                    console.log("Everything looks good! No problems here!.");
                }
              });
          } catch (err) {
              // Handle any errors raised by the code in the try block
          }
      }).catch(err => {
          // Handle errors that may have occurred during initialization
      });
    }
    
    main();
    

    问候

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-05
      • 1970-01-01
      • 2022-08-19
      • 2012-06-20
      • 1970-01-01
      • 1970-01-01
      • 2017-02-07
      相关资源
      最近更新 更多