我正在尝试在 Python 2.4.4 的 .tex 文件上运行 pdflatex。子进程(在 Mac 上):
import subprocess
subprocess.Popen(["pdflatex", "fullpathtotexfile"], shell=True)
这实际上什么也不做。但是,我可以在终端中运行“pdflatex fullpathtotexfile”而不会出现问题,生成 pdf。我缺少什么?
[编辑]
正如其中一个答案所建议的,我尝试过:
return_value = subprocess.call(['pdflatex', '/Users/Benjamin/Desktop/directory/ON.tex'], shell =False)
失败并显示:
Traceback (most recent call last):
File "/Users/Benjamin/Desktop/directory/generate_tex_files_v3.py", line 285, in -toplevel-
return_value = subprocess.call(['pdflatex', '/Users/Benjamin/Desktop/directory/ON.tex'], shell =False)
File "/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/subprocess.py", line 413, in call
return Popen(*args, **kwargs).wait()
File "/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/subprocess.py", line 543, in __init__
errread, errwrite)
File "/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/subprocess.py", line 975, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
该文件确实存在并且我可以运行pdflatex /Users/Benjamin/Desktop/directory/ON.tex
在终端中。请注意, pdflatex 确实会抛出大量警告...但这并不重要,并且这也会给出相同的错误:
return_value = subprocess.call(['pdflatex', '-interaction=batchmode', '/Users/Benjamin/Desktop/directory/ON.tex'], shell =False)