python - 在 Web 服务器中时无法从 Python 打印(到打印机)
问题描述
我可以使用此代码将作业发送到我的系统打印机:
lpr = subprocess.Popen("/usr/bin/lpr", stdin=subprocess.PIPE, close_fds=True)
print('printing from shell!')
lpr.stdin.write(b'print from python')
print('printed!')
但是,如果我在网络服务器中使用此代码,代码会运行,但打印机不会打印。
import http.server
import socketserver
import subprocess
def print_out(a,b,c):
lpr = subprocess.Popen("/usr/bin/lpr", stdin=subprocess.PIPE, close_fds=True)
print('printing from shell!')
lpr.stdin.write(b'print from python')
print('printed!')
PORT = 8080
with socketserver.TCPServer(("", PORT), print_out) as httpd:
print("serving at port", PORT)
httpd.serve_forever()
即使我print_out()
在创建服务器(即上面PORT = 8080
)之前尝试调用也是如此。
我怎样才能使这项工作?
解决方案
推荐阅读
- css - 对称按钮 css 样式
- c# - 程序在没有调试器的情况下运行不同
- android - Android模拟器在顶部显示大透明块
- c++ - 具有概念的显式专业化
- r - 我不明白这个错误:尝试应用非功能
- java - 为什么我打开应用程序时应用程序崩溃?
- firebase - Flutter firebase 使用 collectionGroup 与 where
- mongodb - .Net Core + MongoDb 根据实体自动创建数据库
- c# - 为相机视图创建一个 2D 盒子碰撞器
- google-kubernetes-engine - 尝试在 kubernetes 上部署服务,但我不断收到错误此错误“服务“服务名称”无效:spec.ports:必需值”