← 返回
未分类

Windows 图片打印

Print images on Windows via mspaint /pt using Python — bypasses bash Chinese path encoding issues.
Print images on Windows via mspaint /pt using Python — bypasses bash Chinese path encoding issues.
user_6da1df82
未分类 community v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 12
下载
💾 0
安装
1
版本
#latest

概述

Windows Print Image

Print an image file to a specified printer on Windows. Uses Python subprocess + mspaint /pt to avoid bash/git-bash Chinese path encoding problems.

Trigger

  • User asks to print an image/file
  • User mentions printing something on Windows

Steps

1. Confirm file exists

python -c "import os; print(os.path.exists(r'<absolute_path>'))"

2. List available printers (optional)

powershell -Command "Get-Printer | Select-Object Name, PrinterStatus | Format-Table -AutoSize"

Check default printer:

powershell -Command "(Get-WmiObject -Query 'SELECT * FROM Win32_Printer WHERE Default=True').Name"

3. Print the image

python -c "import subprocess; img = r'<absolute_path>'; prn = '<printer_name>'; subprocess.run(['mspaint', '/pt', img, prn])"

Critical: Use Python raw strings (r'...') for paths — this is what makes it work! Bash's cmd /c mspaint /pt fails with Chinese paths due to encoding corruption, but Python's raw strings preserve the exact bytes.

Example

python -c "import subprocess; img = r'E:\私域相关资料\南京泊宁资料\8888.jpg'; prn = 'Canon G3000 series Printer (副本 1)'; subprocess.run(['mspaint', '/pt', img, prn])"

Pitfalls

  • Do NOT use cmd /c mspaint /p or cmd /c mspaint /pt from bash — Chinese path encoding gets mangled.
  • Do NOT use powershell Start-Process -Verb Print — it pops up a dialog requiring manual confirmation.
  • Always use Python r'...' raw strings for paths.
  • mspaint /pt takes: mspaint /pt — just 2 params is enough, no need for driver/port.

Verification

  • returncode: 0 = print job sent successfully.
  • Check the printer's physical output tray.

版本历史

共 1 个版本

  • v1.0.0 首次发布:解决 Windows bash 环境中文路径编码问题,通过 Python raw string + mspaint /pt 一键打印图片 当前
    2026-06-10 02:52 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-agent

Skill Vetter

spclaudehome
AI智能体技能安全预审工具。安装ClawdHub、GitHub等来源技能前,检查风险信号、权限范围及可疑模式。
★ 1,226 📥 267,804
ai-agent

self-improving agent

pskoett
捕获经验教训、错误及修正内容,以实现持续改进。适用于以下场景:(1)命令或操作意外失败;(2)用户纠正Claude(如“不,那不对……”“实际上……”);(3)用户请求的功能不存在;(4)外部API或工具出现故障;(5)Claude发现自身
★ 4,081 📥 809,926
dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 676 📥 325,412