Subprocess module

G

Guest

Hello all

I want to convert a tex file into a pdf by using pdflatex. For that, I thought the 'subprocess' module might be a good option. My code doesn't work at all tho:

Import os, subprocess

def main():
scriptpath = os.path.dirname(__file__)

p = subprocess.Popen("pdflatex --include-directory=%s --output-directory=%s/output --aux-directory=%s/temp --interaction=nonstopmode myFile.tex"
% (scriptpath, scriptpath, scriptpath),
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
cwd=scriptpath)
(child_stdin,
child_stdout,
child_stderr) = (p.stdin, p.stdout, p.stderr)
print 'stdin'
print child_stdin
print 'stdout'
print child_stdout
print 'stderr'
print child_stderr

When I run that code I get the following printouts:

stdin
<open file '<fdopen>', mode 'wb' at 0x009E7968>
stdout
<open file '<fdopen>', mode 'rb' at 0x009E7A40>
stderr
<open file '<fdopen>', mode 'rb' at 0x009E79F8>
Done

The pdf file however is not created, nor are there any tex-temporary files (like *.log or *.aux) created. If I include a 'p.wait()' I see the python.exe and the pdflatex.exe processes are running, but I have it to terminate them manually (they never finish). My system is winXP btw.

Does anyone have an idea what could be wrong? The reason why I want to use the Popen class is because it has the wait() function, so I can wait for the childprocess (pdflatex) to terminate before I start it again (because you need to run pdflatex several times to get all the references/index things correct in the generated pdf).

Thanks for help,
Dominique
 
D

Diez B. Roggisch

Hello all

I want to convert a tex file into a pdf by using pdflatex. For that, I thought the 'subprocess' module might be a good option. My code doesn't work at all tho:

Import os, subprocess

def main():
scriptpath = os.path.dirname(__file__)

p = subprocess.Popen("pdflatex --include-directory=%s --output-directory=%s/output --aux-directory=%s/temp --interaction=nonstopmode myFile.tex"
% (scriptpath, scriptpath, scriptpath),
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
cwd=scriptpath)
(child_stdin,
child_stdout,
child_stderr) = (p.stdin, p.stdout, p.stderr)
print 'stdin'
print child_stdin
print 'stdout'
print child_stdout
print 'stderr'
print child_stderr

When I run that code I get the following printouts:

stdin
<open file '<fdopen>', mode 'wb' at 0x009E7968>
stdout
<open file '<fdopen>', mode 'rb' at 0x009E7A40>
stderr
<open file '<fdopen>', mode 'rb' at 0x009E79F8>
Done


Just a guess - but how about consuming the very verbose latex ouptut?
Otherwise latex will stop when the stdout-pipe is full.

And beware of the interactive prompte of latex - that thing has bitten
me more than once.

Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top