从python中的ghostscript获取输出

2024-04-23 23:13:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用python编写一个使用gs的脚本,但是我无法从gs获得完整的输出。下面是一个最小的python代码:

import subprocess

filename = "bw_dataset"
output = subprocess.Popen(["gswin64c.exe", "-o nul -sDEVICE=bbox", filename + ".pdf"], stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()[0].decode()

print(output)

如果我在终端(windows)中运行该命令,我会得到一些%%BoundingBox和{}的信息,我需要在脚本中进一步了解这些信息: enter image description here

{py>但是,^从上面的脚本返回: enter image description here

因此边界框信息丢失。我如何将其存储在变量中?在


Tags: 代码import脚本gs信息outputfilenameexe