我正在尝试在 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)