Python 3无法在Windows 10中向网络打印机发出lpr命令

问题描述

我正在尝试使我们的某些打印自动化。 该命令已从PowerShell或cmd.exe Shell正确发出。 下面是PowerShell版本,然后是cmd.exe版本。

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"

当我尝试通过Python 3运行它时,它返回错误代码1。 我已经修改了大约3个小时。我试过使用system(command)函数,但不确定使用哪个shell?我假设使用cmd.exe。我已经验证了PowerShell和cmd.exe的命令都是正确的,并且都尝试了。

这是我的Python尝试:

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

我也尝试过:

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

我在这里不知所措...

感谢您的帮助。

解决方法

因此,事实证明,这也可以通过COPY命令来完成。 我已将其用于我的Post Script打印需求。

我们的服务器为“ joe”,我们的打印机在网络上名为“ Ricoh-A”。 以下命令似乎效果更好。

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

一旦我转义了字符串反斜杠,就成功地从Python调用了它。 我现在要使用它。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...