Running lpr on windows from python

eryk sun eryksun at gmail.com
Fri Apr 22 13:04:24 EDT 2016


On Fri, Apr 22, 2016 at 10:07 AM, loial <jldunn2000 at gmail.com> wrote:
> I finally found the solution here :
>
> http://www.tomshardware.co.uk/forum/240019-44-error-windows
>
> Copied lpr.exe, lprhelp.dll, and lprmonui.dll from the System32 folder to the sysWOW64 folder

Using the virtual "SysNative" directory should work on Windows 7+
(Server 2008 R2). All you need is for CreateProcess to find the
executable. Finding the DLLs is done during process initialization, so
there's no need to copy them from the native System32 directory.

It works for me in 32-bit Python running in Windows 10:

    >>> if '32bit' in platform.architecture():
    ...     lpr = os.path.join(os.environ['SystemRoot'], 'SysNative', 'lpr.exe')
    ... else:
    ...     lpr = os.path.join(os.environ['SystemRoot'], 'System32', 'lpr.exe')
    ...
    >>> print(lpr)
    C:\Windows\SysNative\lpr.exe
    >>> subprocess.call(lpr)

    Sends a print job to a network printer

    Usage: lpr -S server -P printer [-C class] [-J job] [-o option]
[-x] [-d] filename

    Options:
          -S server    Name or ipaddress of the host providing lpd service
          -P printer   Name of the print queue
          -C class     Job classification for use on the burst page
          -J job       Job name to print on the burst page
          -o option    Indicates type of the file (by default assumes
a text file)
                       Use "-o l" for binary (e.g. postscript) files
          -x           Compatibility with SunOS 4.1.x and prior
          -d           Send data file first1



More information about the Python-list mailing list