Subprocess module
Christian Heimes
lists at cheimes.de
Wed Apr 23 08:58:00 EDT 2008
Dominique.Holzwarth at ch.delarue.com schrieb:
> 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 pdflatex job stales when the standard stream buffers are full. Why
do you need stdin anyway? The community method should do the trick for you:
out, err = p.communicate()
I also suggest you use the form ["pdflatex",
"--include-directory="+scriptpath ...] instead of a single string +
shell=True.
Christian
More information about the Python-list
mailing list