开发者

Why doesn't pdflatex work when called as a Python subprocess?

I am trying to implement a function in my Python script to compile a TeX file automatically. I am trying with the subprocess module; this is what I'm doing:

def createpdf(output):
    args = ['pdflatex', output, '-interaction=nonstopmode']

    process = subprocess.call(args,
                    stdout = subprocess.PIPE,
                    stderr = subprocess.PIPE,
                    stdin  = subpr开发者_StackOverflow中文版ocess.PIPE)

When I run pdflatex with my TeX file in the terminal, it compiles fine. But when I run my Python script, it doesn't compile. It seems like the compile process begins but after a couple of minutes, it stops without any reason. I looked in the log file and it doesn't print any error message.


When you set an output pipe to subprocess.PIPE, subprocess creates a buffer to hold the subprocess' output until it's read by your process. If you never read from process.stdout and process.stderr, pdflatex can fill up the buffer and block.

You need to either discard their output or just call subprocess.call(args) and let them flow through your program's output.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜