我目前有以下代码:
subprocess.call(["png2pos", "-c", "example_2.png", ">", "/dev/usb/lp0"])
程序png2pos正在被访问,因为它给我的信息是:
This utility produces binary sequence printer commands. Output have to be redirected
如果我忘记键入>;/dev/usb/lp0,则会出现相同的错误,因此我相当确定它与“>;”字符有关。如何使用子进程将这个输出重定向到/dev/usb/lp0?在
要确保正确重定向输出,需要将
shell
设置为True
,并传递一个字符串:subprocess.call("png2pos -c example_2.png > /dev/usb/lp0", shell=True)
否则,
">"
将被视为程序参数。在我没有安装你的工具,所以我不能在这里测试。但是以前在使用python重定向控制台应用程序的输出时遇到了一个问题。我不得不使用命令本身重定向它,而不是通过shell(正如您正在尝试的那样)
相关问题 更多 >
编程相关推荐