You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python的subprocess/os打印文件时打印任务在队列中停滞

问题:Python生成PDF后打印任务在队列中显示“STOPPED”

成功生成目标PDF文件,但在Ubuntu 22.04、Python 3.10环境下打印时遇阻:

  • 尝试过pycups、subprocess.run、os.system三种方式,代码执行后文件生成正常,打印任务能发送至打印机,但队列中显示为“STOPPED”
  • 手动在终端执行lp命令却能正常打印

因需处理数百个文件,希望能在Python中完成打印并删除文件,而非手动批量处理。

相关代码如下:

with open(examfile, "wb") as fp:
    writer.write(fp)
    conn.printFile(results.printer, examfile, " ", {"Staple","1"})

    # os.system("lp -d " + results.printer + " -o Staple=1 " + examfile)
    # subprocess.run(["lp","-d",results.printer,"-o","Staple=1",examfile],capture_output=True)

注:results.printer和examfile分别为打印机名称和文件名字符串。

内容的提问来源于stack exchange,提问作者user808856

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 12:34:50