I've written a software using node.js and now I'am in need of the posssibility to use a usb printer. Like telling via client to print something out on a printer which is connected per usb to the node.js-server. I also wondered if I can execute an exe by node.js, shellexecute style. I've searched enough to justify this question.
I appreciate any hint.
I've found a solution ... not exactly what I wished for, but here an example:
var exec = require('child_process').exec;
var Data = '';
for (var i=0; i<10; i++){Data+=i+' '}
exec('printit.bat '+Data,
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
I execute a bat file in the root of my server.js file with given parameters (here just a count from 0 to 9, therefore 10 parameters to a bat file) so I can simply handle it there or even use an executable.
There is a command in windows, called print. By using this command, like print /d:\networkprinterpath\printer1 c:\filetoprint.txt In my case, I use a special printer for receipts - a thermo printer. Those printers have a function, that cuts the paper. To add this function to the print, you have to add the special hexcode to the end of the file. As example my printer is an Epson TM-88 IV and to the end of file, I had success with the hex code 1D 56 42 FF. That should be appliable on ever TM-88 printer.
I've gone through your question and there's a node.js package that binds printers on POSIX and Windows OS.
Check it at https://github.com/tojocky/node-printer
cheers,