Skip to content Skip to sidebar Skip to footer

Pdflatex In A Python Subprocess On Mac

I'm trying to run pdflatex on a .tex file from a Python 2.4.4. subprocess (on a mac): import subprocess subprocess.Popen(['pdflatex', 'fullpathtotexfile'], shell=True) which effec

Solution 1:

Use the convenience function, subprocess.call

You don't need to use Popen here, call should suffice.

For example:

>>> import subprocess
>>> return_value = subprocess.call(['pdflatex', 'textfile'], shell=False) # shell should be set to False

If the call was successful, return_value will be set to 0, or else 1.

Usage of Popen is typically for cases when you want the store the output. For example, you want to check for the kernel release using the command uname and store it in some variable:

>>> process = subprocess.Popen(['uname', '-r'], shell=False, stdout=subprocess.PIPE)
>>> output = process.communicate()[0]
>>> output
'2.6.35-22-generic\n'

Again, never set shell=True.


Solution 2:

You might want either:

output = Popen(["pdflatex", "fullpathtotexfile"], stdout=PIPE).communicate()[0]
print output

or

p = subprocess.Popen(["pdflatex" + " fullpathtotexfile"], shell=True)
sts = os.waitpid(p.pid, 0)[1]

(Shamelessly ripped from this subprocess doc page section ).


Post a Comment for "Pdflatex In A Python Subprocess On Mac"