Skip to content

Commit

Permalink
Modified tex2pdf to fail without hanging
Browse files Browse the repository at this point in the history
This can happen when files are missing. pdflatex asks for files via stdin, but
tex2pdf is capturing stdout to make up for pdflatex not providing a valid
integer returncode to indicate failure.
  • Loading branch information
jaberg committed May 14, 2013
1 parent 378bfc9 commit 7505835
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions publisher/build_paper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os.path
import sys
import re
import tempfile
import glob
import shutil

Expand Down Expand Up @@ -88,17 +89,33 @@ def tex2pdf(out_path):
command_line = 'cd %s ' % out_path + \
' ; pdflatex -halt-on-error paper.tex'

run = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE)
# -- dummy tempfile is a hacky way to prevent pdflatex
# from asking for any missing files via stdin prompts,
# which mess up our build process.
dummy = tempfile.TemporaryFile()
run = subprocess.Popen(command_line, shell=True,
stdin=dummy,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = run.communicate()

run = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE)
out, err = run.communicate()
# -- returncode always 0, have to check output for error
if "Fatal" not in out:
# -- pdflatex has to run twice to actually work
run = subprocess.Popen(command_line, shell=True,
stdin=dummy,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = run.communicate()

if "Fatal" in out:
if "Fatal" in out or run.returncode:
print "PDFLaTeX error output:"
print "=" * 80
print out
print "=" * 80
if err:
print err
print "=" * 80

return out

Expand Down

0 comments on commit 7505835

Please sign in to comment.