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 = subprocess.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 fromprocess.stdoutandprocess.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.