TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wrote a Python script to automate some LaTeX builds. Currently I develop/test on Mac OS X (did not try it on other UNIX flavors).

The particular execution function which should compile the LaTeX into a pdf document looks like:

def execute(texinputs, params, proj_dir):
    latex_cmd = '/usr/texbin/xelatex'

    if params is None or len(params)==0:
        params = [latex_cmd]
        params.insert(0, latex_cmd)

    environment = os.environ
    oldenv = environment.get('TEXINPUTS', '')
    prepand = ':'.join([input for input in texinputs])
    ptoken=subprocess.Popen(params, env=environment, cwd=proj_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    with ptoken.stdout as stdout:
        with ptoken.stderr as stderr:
            for _i in range(1,10):
                if ptoken.poll() is None:
            if ptoken.returncode is None:
                ret = -1000
            outlines, errlines = stdout.readlines(), stderr.readlines()
            return ret, outlines, errlines 

What I do here is passing the paths to some generated sources which should be pre-pended to TEXINPUTS to resolve relative paths inside my LaTeX template as well as some additional tex processor parameters.

A typical shell command call (which works fine) is:

TEXINPUTS=/Users/ovanes/Documents/some_path/content:$TEXINPUTS /usr/texbin/xelatex -shell-escape main.tex

This produces a main.pdf which is fine. However, running this shell command from the script I see the following output and no main.pdf is written.

Error 32512 (driver return code) generating output;
file main.pdf may not be valid.

Any ideas?

share|improve this question

migrated from meta.tex.stackexchange.com Jun 27 '11 at 10:44

This question came from our discussion, support, and feature requests site for users of TeX, LaTeX, ConTeXt, and related typesetting systems.

TeX related questions should be asked at TeX.SX (tex.stackexchange.com). The meta.tex.stackexchange.com site you posted it is for discussions, bug reports etc. about TeX.SX. I migrated it to the right place. – Martin Scharrer Jun 27 '11 at 10:46
check this, maybe it suits your needs. bitbucket.org/ms4py/latexmk.py/wiki/Home – pmav99 Jun 27 '11 at 11:00
Thanks for help, but not really. My builder can generate dynamic content which can be embedded into the existing LaTeX template. Smth. like writing a letter to all your customers requires you to generate for each customer personalized letter. This python script, can update the address field and recompile the document. It is not like conventional build systems. – ovanes Jun 29 '11 at 19:33
up vote 4 down vote accepted

Ok, I found out the problem. I overlooked that LaTeX processer could not start xdvipdfmx due to path problems. Finally, appending '/usr/texbin' to the PATH environment of the child process worked fine.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.