1. const iconv = require('iconv-lite');
    2. function bianma(data) {
    3. //win一般控制台是cp936编码,根据自己实际情况替换
    4. data = iconv.decode(data, 'cp936');
    5. return data.toString('utf-8');
    6. }
    7. const { exec } = require('child_process');
    8. exec('net session', { encoding: 'buffer' }, (error, so, se) => {
    9. console.log(1, bianma(Buffer.from(error ? JSON.stringify(error) : '')));
    10. console.log(2, so ? bianma(so) : so);
    11. console.log(4, bianma(se), se.length);
    12. });