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
}

标签: js, node, windows, 打印机

添加新评论