Python 3 can't issue lpr command to a networked printer in Windows 10

238 Views Asked by At

I'm trying to automate some of our printing. The command has been issued from PowerShell or cmd.exe shell correctly. Below I have PowerShell version then cmd.exe version.

lpr -S '192.168.8.200' -Pfiletype=RPS -ol "C:\Users\rburnside\Desktop\Print Test\Hello 2020.09.23.ps"

lpr -S 192.168.8.200 -Pfiletype=RPS -ol "C:\Users\rburnside\Desktop\Print Test\Hello 2020.09.23.ps"

When I try to run it via Python 3 it returns an error code 1. I've tinkered with this for about 3 hours. I've tried using the system(command) function but I'm not sure which shell it uses? I assume cmd.exe. I've verified the command for both PowerShell and cmd.exe is correct and tried both.

Here is my Python attempt:

system("lpr -S '192.168.8.200' -Pfiletype=RPS -ol \"C:\\Users\\rburnside\\Desktop\\Print Test\\Hello 2020.09.23.ps\"")

I've also tried:

system("lpr -S 192.168.8.200 -Pfiletype=RPS -ol \"C:\\Users\\rburnside\\Desktop\\Print Test\\Hello 2020.09.23.ps\"")

I'm at a loss here...

Thanks for your help.

1

There are 1 best solutions below

0
On

So it turns out that this can also be done via the COPY command. I've adopted that for my Post Script printing needs instead.

Our server is "joe" and our printer is named "Ricoh-A" on the network. The following command seems to be working much better.

COPY "path\to\my\postscript\file.ps" "\\joe\Ricoh-A"

That was successfully called from Python once I escaped the string backslashes. I'm going to use this for now.