我试着制作一个网络应用程序,在LQ-310打印机上使用express和QZ打印。但是,我无法按预期执行打印过程,只有当用户到达端点时,如果我将QZ函数放入另一个函数中,它才会触发打印。如果用户触发端点,我尝试为其创建一个专用文件,并使用bash/shell脚本执行该文件:
const printInvoice = (req, res) => {
fs.writeFile(`src/invoice/invoice.json`, JSON.stringify(req.body), (err) => {
if (err) throw err;
});
// shell script to run qz-tray
const shell = require('shelljs');
shell.echo('Running qz-tray');
shell.exec('bash src/invoice/qz-tray.sh');
fs.readFile(`src/invoice/invoice.json`, (err, data) => {
if (err) throw err;
res.json(JSON.parse(data));
});
}但是,我的终端不返回任何结果,甚至不返回错误消息。
我也已经开始只是在一个功能内做路线,但没有发现任何结果。
发布于 2022-10-03 04:19:12
library是最常见的客户端库。这意味着JavaScript调用必须来自客户机(浏览器),而不是服务器(节点)。
这里有一个非常简单的样板layout.jade,让快车+翡翠与QZ交谈。它是建立在快速应用生成器之上的。
# put qz-tray.js in an accessible, public directory
curl -o public/javascripts/qz-tray.js https://raw.githubusercontent.com/qzind/tray/master/js/qz-tray.jsdoctype html
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
/***************************
* code changes start here *
***************************/
script(src='/javascripts/qz-tray.js', type='text/javascript')
script.
qz.websocket.connect().then(() => {
return qz.printers.find()
}).then(printers => {
document.getElementsByTagName("p")[0].innerHTML += "<p>Found printers:</p><ul>";
printers.forEach(printer => {
document.getElementsByTagName("p")[0].innerHTML += "<li>" + printer + "</li>";
});
document.getElementsByTagName("p")[0].innerHTML += "</ul>";
});
/***************************
* end of code changes *
***************************/
body
block contenthttps://stackoverflow.com/questions/73928097
复制相似问题