# Why php exec() fails .tex→xelatex→.pdf, but succeed .tex→xelatex→.xdv→xdvipdfmx→.pdf?

The call of command:

``````\$dir = "/path/to/source/file";
exec("cd \$dir;xelatex filesource.tex", \$output_array[0]);
``````

always fails, but:

``````\$dir = "/path/to/source/file";
exec("cd \$dir;/usr/texbin/xelatex -no-pdf filesource.tex", \$output_array[0]);// now we have .xdv file
exec("cd \$dir;/usr/texbin/xdvipdfmx filesource.xdv", \$output_array[1]);
``````

succeed, and result .pdf file absolutely valid. What is the trick?

-
Getting any errors? –  You Oct 29 '13 at 7:45
XeTeX spawns an `xdvipdfmx` process and pipes shipped out pages to it, unless `--no-pdf` is specified. It's possible that this fools `exec`. –  egreg Oct 29 '13 at 8:56
I suspect xelatex without -no-pdf makes some kind .xdv but lost the path before final compilation. If it is, I want to find the way to fix this failure and understand the whole picture. –  Ruben Kazumov Oct 29 '13 at 15:31
did you try adding the `-output-directory=` option to xelatex? –  Thruston Nov 15 '13 at 11:28
Oh yes! I did it in my first 50 attempts. Xelatex starts produce files to the `-output-directory`, but eventually loses the path and can not find his own .aux file, just a moment ago made by himself. –  Ruben Kazumov Nov 15 '13 at 16:37