1

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.

Jeremy
  • 1
  • 85
  • 340
  • 366
Alejandro
  • 4,945
  • 6
  • 32
  • 30

1 Answers1

1

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.

Community
  • 1
  • 1
Jeremy
  • 1
  • 85
  • 340
  • 366
  • thanks Jeremy... I read in another page that I need those PIPEs but after I remove them everything works perfect.... thanks a lot!!! :) – Alejandro Aug 15 '11 at 16:13