relima
relima

Reputation: 3423

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

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.

Upvotes: 0

Views: 1828

Answers (2)

David Heffernan
David Heffernan

Reputation: 612814

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.

Upvotes: 2

Neil
Neil

Reputation: 55382

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

Upvotes: 3

Related Questions