trouble with shell_exec()

If you aren't familiar with LaTeX, don't stress.. it's just a document markup language that I use for creating Math documents.

Anyway, if I execute "latex /home/destructo/Desktop/example.tex" inside my command prompt (ubuntu), it will create the desired document... I decided to try to create a localhost website to aid with this process and was suggested to use the shell_exec() function. However, I quickly found this to be a problem..

When I use the following code, I receive an error.

$output = shell_exec('latex /home/destructo/Desktop/example.tex');
echo "<pre>$output</pre>";

The error is the following:

I am hoping someone might be able to help me understand why this is happening.. Or if there is an alternate way to accomplish my goals...I am supposing it is a permissions problem..??

Anyway, it's my first post here.. Be kind! >.<

-Tyrick

Good lord, I should have known better than to google "man latex"... :eek:

When you run it yourself, it creates them in the current directory. When you run it from PHP like that, it will try to create them inside the same folder as the PHP script, I think. Probably not a folder you want apache to be able to modify! Give latex a -output-directory parameter to make latex write them somewhere else.

You'll want this folder to have the apache group and be group-writable.

# as root
chown :apache /path/to/folder
chmod g+rwx /path/to/folder

When your webserver creates files in /path/to/folder they will belong to apache:apache. This won't be a problem I think; you should be able to read and delete them since the directory belongs to you. If the permissions aren't permissive enough, you can do chmod o+rw inside your php script after latex finishes.

Secondly, even if you get PHP executing it like that, I don't think PHP is actually going to dump the output file's contents into the variable. I think you'll have to $f=fopen("/path/to/filename"); while($var=fgets($f)) { ... } to process it there.

1 Like

hey.. that was a perfect reply. I've got everything working now. Beautiful! Thank you so much! (Why did you add "man" to that... lol)

If you don't know about UNIX manual pages, you're missing out on a lot. Try typing man latex into your shell. Manual pages should be available for quite a few different commands, utilities, functions, shells, protocols, and system calls. You can also access manual pages on unix.com through the 'man' link in the top bar, though as it turns out, not for latex.