【发布时间】:2017-01-21 23:23:44
【问题描述】:
我可以使用 subprocess.Popen() 从 Python 中打开 PDF 文件,但在关闭 PDF 文件时遇到问题。如何使用 Python 关闭打开的 PDF 文件。我的代码是:
# open the PDF file
plot = subprocess.Popen('open %s' % filename, shell=True)
# user inputs a comment (will subsequently be saved in a file)
comment = raw_input('COMMENT: ')
# close the PDF file
#psutil.Process(plot.pid).get_children()[0].kill()
plot.kill()
编辑:我可以在打开 PDF 后立即关闭它(使用 plot.kill()),但如果在打开 PDF 和“杀死”它之间有另一个命令,这将不起作用。任何帮助都会很棒 - 在此先感谢。
【问题讨论】:
-
@Ewoud 感谢您的指点。我测试了这些示例以关闭我的 PDF 文件,但 PDF 文件仍然打开。你有什么想法吗?