Which shell command can I use In windows (XP or older) to bring me the print picture dialog?

时光总嘲笑我的痴心妄想 提交于 2019-12-25 03:43:28

问题


In Python, if I want to open/launch the default browser using shell, I can import os and execute run "www.google.com". Is there any similar way to open the print pictures dialog for a given image.jpg as if right clicking it and selecting print in the context menu that I can use to call this routine from python???

Thank you.


回答1:


You can call win32api.ShellExecute with the "print" verb. An example: http://timgolden.me.uk/python/win32_how_do_i/print.html




回答2:


At least on my Windows system (Windows 7), there seems to be no trivial way to achieve this. I found that a naive call to ShellExecute appeared to do nothing. Then I tried this:

import time, win32api
win32api.ShellExecute(0, "print", "test.jpg", None, None, 0)
time.sleep(5)

With the addition of the call to sleep() the dialog appeared, but when the python process terminated, the print dialog closed too.

Since the print dialog runs in-process I don't see an easy wait to wait on it. If it were to run as a separate process then it would be trivial to wait on that process.

I suppose a hacky solution would be to run this through pythonw so that no console appeared, and put in a long sleep. You might end up with some stray Python processes that were aimlessly sleeping, but that might not matter.



来源:https://stackoverflow.com/questions/5253846/which-shell-command-can-i-use-in-windows-xp-or-older-to-bring-me-the-print-pic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!