[Tex/LaTex] Calling pdflatex from a Python script

pdftexpython

I wrote a Python script that produces a LaTeX document. It saves it to some folder and tries to compile by

os.system("pdflatex %s" % filename_tex)

where filename_tex is a path to the just produced file. The file is okay as I can open it in TeXnicCenter, call pdflatex and compile. There are no spaces in the path/file name.

However, calling it from the script returns

pdflatex: Permission denied: C:\Users\tiger\Desktop\CT_xls_to_latex\output\myfile.tex
pdflatex: Data: C:\Users\tiger\Desktop\CT_xls_to_latex\output\myfile.tex

I made sure pdflatex is not running in the background. Any ideas are most welcome.

Follow up:

Actually, if I take the file path as it is and paste into the script, then it works:

os.system(r"pdflatex C:\Users\tiger\Desktop\CT_xls_to_latex\output\myfile.tex")

I am extremely confused by this behaviour. How come os.system does not like string substitution?

Best Answer

I don't know what was the reason but here is the fix.

inputted_path = r"\input{"+filepath+"}"
os.system("pdflatex %s" % inputted_path)