node调用windows指定打印机
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
}