标签 node 下的文章

nexe build

nexe main.js --build

ℹ nexe 4.0.0-rc.6
✔ Already downloaded...
✔ Configuring node build: --dest-cpu=x64
✔ Finished in 5.814s

Error: python ./configure.py --dest-cpu=x64 exited with code: 1

See nexe -h for usage..

指定python版本

#nexe build specify python
export PYTHON=/Library/Frameworks/Python.framework/Versions/3.7/bin/python3

node 调用powershell

const {exec} = require("child_process");

const printByPowerShell = (filePath, printerName) => {
    const command = `Get-Content "${filePath}" | Out-Printer -Name "${printerName}"`;

    exec(`powershell.exe -Command "${command}"`, (error, stdout, stderr) => {
        if (error) {
            console.error(`Error executing command: ${error.message}`);
            return;
        }
        if (stderr) {
            console.error(`PowerShell Error: ${stderr}`);
            return;
        }
        console.log(`Output: ${stdout}`);
    });

}

module.exports = {
    printByPowerShell
}

const hexString = "68656c6c6f";
const byteArray = Buffer.from(hexString, 'hex');
console.log(byteArray);

由于浏览器不支持Buffer,使用下面的形式

const hexStringToByteArray = function (hexString) {
    const bytes = new Uint8Array(hexString.length / 2);

    for (let i = 0; i < hexString.length; i += 2) {
        bytes[i / 2] = parseInt(hexString.substr(i, 2), 16);
    }

    return bytes;
}